Analysis of a histogram of image colors (RGB)
Source code name: "image_histo.py"
Programming language: Python
Topic: Images/Analysis
DMelt Version 1. Last modified: 03/03/2021. License: Pro
https://datamelt.org/code/cache/image_histo_6529.py
To run this script using the DMelt IDE, copy the above URL link to the menu [File]→[Read script from URL] of the DMelt IDE.


 
from ij import *
from ij.process import *
from jhplot import *
from jhplot.utils import ColorPixel
from java.awt import Color

imp = IJ.openImage("https://datamelt.org/logo.png")
imp.show()
# Returns an RGB version of this image as a ColorProcessor.
pix=imp.getProcessor().convertToRGB().getPixels()

rgb=ColorPixel.getP0I(pix) # get pixels in the usual R,G,B 

c1 = HPlot("Image colors",500,500,1, 3)
c1.setGTitle("Histogram of image colors")
c1.visible()

red = H1D("Red",125, 0, 255)
green = H1D("green",125, 0, 255)
blue = H1D("blue", 125, 0, 255)

red.setFill(1)
red.setColor(Color.red)
red.setFillColor(Color.red)

green.setFill(1)
green.setColor(Color.green)
green.setFillColor(Color.green)

blue.setFill(1)
blue.setColor(Color.blue)
blue.setFillColor(Color.blue)

red.fill(rgb[0])     # fill histograms in one go
green.fill(rgb[1])
blue.fill(rgb[2])

# fill histograms
max=200
c1.cd(1,1)
c1.setRange(0,255,0,max)
c1.draw(red)

c1.cd(1,2)
c1.setRange(0,255,0,max)
c1.draw(green)

c1.cd(1,3)
c1.setRange(0,255,0,max)
c1.draw(blue)




You see the box below because you did not login.