Macro for a selection of the particles with color thresholding, than rgb with color histogram, than save results as image name

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Macro for a selection of the particles with color thresholding, than rgb with color histogram, than save results as image name

PAMALE
This post was updated on .
Hello guys!

I hope you can help me.
I came quite far but the code is not all good yet.

At the moment I'm writing my thesis and I'm trying to automatize my analyzes a bit.
I have to measure the rgb values of dried, slized apples.
For selecting them correctly i want to use COLOR THRESHOLD.
The RGB Values i measure with color histogram.
The results i want to save in the same file as the image was, with the same name, for importing them into excel later on.

Before I run the macro, I open the picture I want to analyze.
So far the macro looks like this:

if(nImages>0)
{
title = getTitle();
directory = File.directory;


run("Color Threshold...");

selectWindow(title);
run("Color Histogram");

saveAs("Results", directory+title+".txt");
}

The Problem is that the Color Thresholder, does not
have the right settings (huang, red, rgb)
and does not automatically run the select button.

I'll tried to use the code from the macro recording:
run("Color Threshold...");
// Color Thresholder 1.50i
// Autogenerated macro, single images only!
min=newArray(3);
max=newArray(3);
filter=newArray(3);
a=getTitle();
run("RGB Stack");
run("Convert Stack to Images");
selectWindow("Red");
rename("0");
selectWindow("Green");
rename("1");
selectWindow("Blue");
rename("2");
min[0]=0;
max[0]=173;
filter[0]="pass";
min[1]=0;
max[1]=138;
filter[1]="pass";
min[2]=0;
max[2]=134;
filter[2]="pass";
for (i=0;i<3;i++){
  selectWindow(""+i);
  setThreshold(min[i], max[i]);
  run("Convert to Mask");
  if (filter[i]=="stop")  run("Invert");
}
imageCalculator("AND create", "0","1");
imageCalculator("AND create", "Result of 0","2");
for (i=0;i<3;i++){
  selectWindow(""+i);
  close();
}
selectWindow("Result of 0");
close();
selectWindow("Result of Result of 0");
rename(a);
// Colour Thresholding-------------


But this didn't worked at all.

Instead of selecting the slices, it opened several windows and in the end color histogram couldn't read the rgb anymore.
Do you have any solutions for me?

Thank you

Patrick