Hi, I have a simple problem but I can't find solution anywhere.
I have a few stacks with 50 images, every image has 6 colors. I want to know the number of pixels of every color for individual images not for whole stack. I know I can find it under Analyze > Histogram > List but I have to do it for every single image. It is a lengthy process. Is there some option/plugin to do this for all images at once? Vojtech Skala, CTU in Prague -- Sent from: http://imagej.1557.x6.nabble.com/ -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Dear Vojtech,
The macro at https://imagej.nih.gov/ij/macros/StackHistogramLister.txt will probably do what you want imagej.nih.gov<https://imagej.nih.gov/ij/macros/StackHistogramLister.txt> // This macro prompts for the bin count and histogram // min and max and then writes the histogram counts of // the current image or stack to the "Results" window. imagej.nih.gov Best wishes Kees ________________________________ Hi, I have a simple problem but I can't find solution anywhere. I have a few stacks with 50 images, every image has 6 colors. I want to know the number of pixels of every color for individual images not for whole stack. I know I can find it under Analyze > Histogram > List but I have to do it for every single image. It is a lengthy process. Is there some option/plugin to do this for all images at once? Vojtech Skala, CTU in Prague -- Sent from: https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fimagej.1557.x6.nabble.com%2F&data=02%7C01%7Ckrs5%40leicester.ac.uk%7Cce1efecc5ca7469673ae08d806db0c98%7Caebecd6a31d44b0195ce8274afe853d9%7C0%7C1%7C637266885181683123&sdata=5%2BVGwiJTNYnlTK3TshFBDAZu0uECtrJ6tHY4tH9RxGw%3D&reserved=0 -- ImageJ mailing list: https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fimagej.nih.gov%2Fij%2Flist.html&data=02%7C01%7Ckrs5%40leicester.ac.uk%7Cce1efecc5ca7469673ae08d806db0c98%7Caebecd6a31d44b0195ce8274afe853d9%7C0%7C1%7C637266885181683123&sdata=8iP7kKg3Yczx%2B%2Fv5CEwY5sm4O9WJiW2FWemDIDy%2FBH4%3D&reserved=0 -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
That is exactly what I need, thank you very much Kees!
Best wishes, Vojtěch -- Sent from: http://imagej.1557.x6.nabble.com/ -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
This updated code might make life a little easier
// This macro prompts for the bin count and histogram // min and max and then writes the histogram counts of // the current image or stack to the "Results" window. requires("1.34m"); Dialog.create("Histogram Lister"); Dialog.addNumber("Number of Bins:", 256); Dialog.addNumber("Histogram Min:", 0); Dialog.addNumber("Histogram Max:", 256); Dialog.show(); nBins = Dialog.getNumber(); hMin = Dialog.getNumber(); hMax = Dialog.getNumber(); row=0; run("Clear Results"); setBatchMode(true); stack = getImageID(); for(slice=1; slice<=nSlices; slice++){ row = 0; selectImage(stack); if (nSlices>1) run("Set Slice...", "slice=" + slice); if (bitDepth!=32){ run("Duplicate...", "title=temp"); run("32-bit"); } getHistogram(values,counts,nBins,hMin,hMax); close(); for (i=0; i<nBins; i++) { if (nSlices>1) setResult ("Bin", row, values[i]);//setResult("Slice", row, slice); setResult("Image"+"Slice"+slice, row, counts[i]); row++; } } updateResults(); Best wishes Kees ________________________________ That is exactly what I need, thank you very much Kees! Best wishes, Vojtěch -- Sent from: https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fimagej.1557.x6.nabble.com%2F&data=02%7C01%7Ckrs5%40leicester.ac.uk%7C7bd7d12edce940805a5508d806ea0a01%7Caebecd6a31d44b0195ce8274afe853d9%7C0%7C1%7C637266949553236629&sdata=wr8nzpGze5d6e1qy%2BHXdw%2Bm1aNv0SaW4QaoaOc%2B6%2Frk%3D&reserved=0 -- ImageJ mailing list: https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fimagej.nih.gov%2Fij%2Flist.html&data=02%7C01%7Ckrs5%40leicester.ac.uk%7C7bd7d12edce940805a5508d806ea0a01%7Caebecd6a31d44b0195ce8274afe853d9%7C0%7C1%7C637266949553236629&sdata=oWrRnN%2BOz3UatqklxlJSzewCUDY9ZOpdll0vumznjxA%3D&reserved=0 -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Now it is perfect, you are the best Kees, thank you.
-- Sent from: http://imagej.1557.x6.nabble.com/ -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Can do one better; gives a results table with slice, channel and frame number in the table heading
--------------------------------------------- requires("1.34m"); if (nImages == 0) exit("This macro requires an open image."); Dialog.create("Histogram Lister"); Dialog.addNumber("Number of Bins:", 256); Dialog.addNumber("Histogram Min:", 0); if (bitDepth==16) Dialog.addNumber("Histogram Max:", 65536); else Dialog.addNumber("Histogram Max:", 256); Dialog.show(); nBins = Dialog.getNumber(); hMin = Dialog.getNumber(); hMax = Dialog.getNumber(); run("Clear Results"); setBatchMode(true); stack = getImageID(); for(s=1; s<=nSlices; s++){ row = 0; selectImage(stack); if (nSlices>1) run("Set Slice...", "slice=" + s); Stack.getPosition(channel, slice, frame); run("Duplicate...", "title=temp"); if (bitDepth!=32) run("32-bit"); getHistogram(values,counts,nBins,hMin,hMax); close(); for (i=0; i<nBins; i++) { if (nSlices>1) setResult ("Bin", row, floor(values[i])); setResult("Slice"+slice+"-Channel"+channel+"-frame"+frame, row, counts[i]); row++; } } updateResults(); ---------------------------------------- Kees -- Sent from: https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fimagej.1557.x6.nabble.com%2F&data=02%7C01%7Ckrs5%40leicester.ac.uk%7C146e8cad9e0541432d4d08d806f36f69%7Caebecd6a31d44b0195ce8274afe853d9%7C0%7C1%7C637266989904236581&sdata=U5qOsxPwjVhGTk8xLASIYa8XqGp9ZkADQiiMQZLtDyc%3D&reserved=0 -- ImageJ mailing list: https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fimagej.nih.gov%2Fij%2Flist.html&data=02%7C01%7Ckrs5%40leicester.ac.uk%7C146e8cad9e0541432d4d08d806f36f69%7Caebecd6a31d44b0195ce8274afe853d9%7C0%7C1%7C637266989904236581&sdata=1Qy9S%2FkNTZ5%2Fqo751RIUOM3wGmtmUoZCwGJwA40fBNI%3D&reserved=0 -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Free forum by Nabble | Edit this page |