Login  Register

Re: Threshold problems

Posted by Anderson, Charles (DNR) on Oct 14, 2013; 4:34pm
URL: http://imagej.273.s1.nabble.com/Threshold-problems-tp5005085p5005168.html

Leila,

Try something like this, and remove all the other 'setThreshold',  runThreshold, and setAutothreshold lines.
    setAutoThreshold("Huang");   // or other method
    run("Convert to Mask");  // display white 0 on black 255
    //run("Threshold...");
    //setAutoThreshold("Default");
    //setThreshold(u0, 65535);
You may need to try setAutoThreshold("Huang dark");  or add run("Invert"); depending on your images.

At the end of your macro, do you get what you need with just two lines?  Areas of each particle.
//    id = getImageID();
//    selectImage(id+1);
    sourceTitle = getTitle();
//    selectImage(id);
    run("Set Measurements...", "area mean min display decimal=3");
//    run("Set Measurements...", "area mean min display redirect=["+sourceTitle+ "] decimal=3");
    run("Analyze Particles...", "size=90-350 pixel circularity=0.00-1.00 show=Outlines display");
//    selectImage(id+2);
//    sourceTitle = getTitle();
//    selectImage(id);
//    run("Set Measurements...", "area mean min display redirect=["+sourceTitle+ "] decimal=3");
//    run("Analyze Particles...", "size=90-350 pixel circularity=0.00-1.00 show=Outlines display include");

Or if you want total area of all the particle masks
run("Analyze Particles...", "size=90-350 circularity=0.00-1.00 show=Masks display");
run("Measure");

Charles

-----Original Message-----
From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Leila Alieh
Sent: Saturday, October 12, 2013 4:28 AM
To: [hidden email]
Subject: Re: Threshold problems

Hello Curtis,

thank you very much for your help!
I studied the link you suggested me but I still have some problem. When I run the Auto Threshold I get an image with colour satured particles (the cells I'm interested in) on a black background (or on the original image in the montage when I run the "Try all" option), I don't get a black on white mask as I was used to.
But the main thing is that when I select a specific method and then I select "Analyze particles" and I choose and appropriate size range I get an error message:

"No particles were detected. The assumed thredhold (0-0) may not be correct"

If I don't choose the size range it counts something near the image borders but not he selected particles (I checked with the outlines).
I tried also to select the algorithm in normal Threshold. In this case it works, I get the mask and it measures the selected particles, but the thresold value is different than the one obtained with the same algorithm in the Auto Threshold method, is it normal?
Once I have chosen the algorithm can I include it in the macro and run it automatically? How should I do?
Then I will also need to measure the entire area of my cut images. Does someone already developed a macro for this? if not do you have any suggestion?

Thank you very much!!!



2013/10/12 Leila Alieh <[hidden email]>

> Hello Curtis,
>
> thank you very much for your help!
> I studied the link you suggested me but I still have some problem.
> When I run the Auto Threshold I get an image with colour satured
> particles (the cells I'm interested in) on a black background (or on
> the original image in the montage when I run the "Try all" option), I
> don't get a black on white mask as I was used to.
> But the main thing is that when I select a specific method and then I
> select "Analyze particles" and I choose and appropriate size range I
> get an error message:
>
> "No particles were detected. The assumed thredhold (0-0) may not be
> correct"
>
> If I don't choose the size range it counts something near the image
> borders but not he selected particles (I checked with the outlines).
> I tried also to select the algorithm in normal Threshold. In this case
> it works, I get the mask and it measures the selected particles, but
> the thresold value is different than the one obtained with the same
> algorithm in the Auto Threshold method, is it normal?
> Once I have chosen the algorithm can I include it in the macro and run
> it automatically? How should I do?
> Here the macro I'm using:
>
>  origen = getDirectory("Images to process"); lista =
> getFileList(origen);
> u0 = getNumber("threshold", u0);
> setBatchMode(true);
> for (i=0; i<lista.length; i++) {
>     showProgress(i+1, lista.length);
>     open(origen+lista[i]);
>     nombre = lista[i];
>     run("Split Channels");
>     run("Duplicate...", "title=[]");
>     run("Subtract Background...", "rolling=50");
>     run("Gaussian Blur...", "sigma=1");
>     setAutoThreshold("Default");
>     //run("Threshold...");
>     setAutoThreshold("Default");
>     setThreshold(u0, 65535);
>     run("Convert to Mask");
>     run("Close-");
>     run("Fill Holes");
>     id = getImageID();
>     selectImage(id+1);
>     sourceTitle = getTitle();
>     selectImage(id);
>     run("Set Measurements...", "area mean min display redirect=["+
> sourceTitle+ "] decimal=3");
>     run("Analyze Particles...", "size=90-350 pixel
> circularity=0.00-1.00 show=Outlines display");
>     selectImage(id+2);
>     sourceTitle = getTitle();
>     selectImage(id);
>     run("Set Measurements...", "area mean min display redirect=["+
> sourceTitle+ "] decimal=3");
>     run("Analyze Particles...", "size=90-350 pixel
> circularity=0.00-1.00 show=Outlines display include");
>     }
>
>
> Then I will also need to measure the entire area of my modified images.
> Does someone already developed a macro for this? if not do you have
> any suggestion?
>
> Thank you very much!!!
>
>
> 2013/10/9 Curtis Rueden <[hidden email]>
>
>> Hi Leila,
>>
>> > What do you mean with the auto-threshold algorithm?
>>
>> An auto-thresholding algorithm chooses a (hopefully) appropriate
>> threshold by analyzing the histogram of your data and guessing at a
>> good cutoff point.
>>
>> See the docs at:
>> http://imagej.net/docs/guide/146-28.html#toc-Subsubsection-28.2.4
>>
>> You can also use Fiji's "Image > Adjust > Auto Threshold" plugin with
>> method of "Try all" to create a mosaic of the mask produced by each
>> auto-thresholding algorithm, which makes the results very easy to
>> compare quickly.
>>
>> Regards,
>> Curtis
>>
>>
>> On Wed, Oct 9, 2013 at 5:02 AM, Leila Alieh <[hidden email]>
>> wrote:
>>
>> > Hi Curtis!!!
>> > Thank you for the reply!
>> > I tried to set the threshold without the macro, to see how reliable
>> > it
>> is.
>> > There is a huge difference in intensity across the images...I
>> > really
>> can't
>> > choose a good threshold for all of them. What do you mean with the
>> > auto-threshold algorithm?
>> >
>> >
>> > 2013/10/8 Curtis Rueden <[hidden email]>
>> >
>> > > Hi Leila,
>> > >
>> > > Are you sure ImageJ isn't autoscaling your display differently
>> > > across
>> > your
>> > > images?
>> > >
>> > > What does the pixel probe say? Mouse over your data and look at
>> > > the
>> raw
>> > > numbers spit out in the main ImageJ window's status bar.
>> > >
>> > > Also, can you use an auto-threshold algorithm across all your
>> > > images
>> to
>> > > make your analysis reproducible without needing to hardcode a
>> > > specific threshold value?
>> > >
>> > > Regards,
>> > > Curtis
>> > >
>> > >
>> > > On Tue, Oct 8, 2013 at 1:56 PM, Leila Alieh
>> > > <[hidden email]>
>> > wrote:
>> > >
>> > > > Hello!
>> > > >
>> > > > I developed a macro to count the number of cells positives for
>> > > > a
>> given
>> > > > antibody. The cells are selected depending on size, circularity
>> > > > and intensity. I found an intensity value good for some images
>> > > > and I run
>> > the
>> > > > macro. After that I found that the choosen threshold is too
>> > > > high for
>> > one
>> > > > image, so that to have a reliable valuation for that image I
>> > > > should
>> use
>> > > > half of the threshold chosen for the other images, but this
>> > > > latter threshold is really too low for the other images and it
>> > > > gives a
>> wrong
>> > > > result. I can't understand why this image is so different
>> > > > because
>> the
>> > > > intensity of the cells is not so different by eyes (it's a good
>> quality
>> > > > image, the ab signal is strong and there are no shadows). I was
>> > wondering
>> > > > if I did some mistake during the "editing": I had to cut the
>> > > > images
>> > (I'm
>> > > > interested only in a small area of them) and save them in a
>> > > > tiff
>> > format.
>> > > Is
>> > > > it possible that this editing chenged the intensity values?
>> > > > Thank you for your help!!!!
>> > > >
>> > > > Leila
>> > > >
>> > > > --
>> > > > ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>> > > >
>> > >
>> > > --
>> > > ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>> > >
>> >
>> > --
>> > ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>> >
>>
>> --
>> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>>
>
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html