Created
July 15, 2021 15:03
-
-
Save mutterer/0f3ee8b3cb51818128e3294996f65e42 to your computer and use it in GitHub Desktop.
An ImageJ macro that draws a RGB Histogram
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
setBatchMode(1); | |
if (bitDepth!=24) exit(); | |
t=getTitle; | |
run("Duplicate...","title="+t); | |
run("Make Composite"); | |
Stack.setChannel(1); | |
getHistogram(values, reds, 256); | |
Array.getStatistics(reds, rmin, rmax, mean, stdDev); | |
Stack.setChannel(2); | |
getHistogram(values, greens, 256); | |
Array.getStatistics(greens, gmin, gmax, mean, stdDev); | |
Stack.setChannel(3); | |
getHistogram(values, blues, 256); | |
Array.getStatistics(blues, bmin, bmax, mean, stdDev); | |
max=Math.max(rmax, Math.max(gmax, bmax)); | |
Plot.create("Histogram of "+t, "Values", "Counts"); | |
Plot.setFrameSize(300, 200); | |
Plot.setLimits(0, values.length, 0, max); | |
Plot.add("filled", values, reds); | |
Plot.setStyle(0, "red,red,1.0,Filled"); | |
Plot.appendToStack; | |
Plot.add("filled", values, greens); | |
Plot.setStyle(0, "green,green,1.0,Filled"); | |
Plot.appendToStack; | |
Plot.add("filled", values, blues); | |
Plot.setStyle(0, "blue,blue,1.0,Filled"); | |
Plot.appendToStack; | |
Plot.add("line", values, reds); | |
Plot.setStyle(0, "red,red,1.0,Line"); | |
Plot.add("line", values, greens); | |
Plot.setStyle(1, "green,green,1.0,Line"); | |
Plot.add("line", values, blues); | |
Plot.setStyle(2, "blue,blue,1.0,Line"); | |
Plot.appendToStack; | |
Plot.show(); | |
run("Z Project...", "projection=[Average Intensity]"); | |
rename("Histogram of "+t); | |
setBatchMode(0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment