Login  Register

Re: Automatically detect circular ROI

Posted by Straub, Volko A. (Dr.) on Nov 14, 2015; 8:03am
URL: http://imagej.273.s1.nabble.com/Automatically-detect-circular-ROI-tp5014946p5014949.html

Dear Maria,

Following my earlier response, I put together a macro that detects the
filter with your colonies, removes the gridlines and counts the colonies
(see code below, also attached as .ijm file). I think it does a
reasonable job on the sample image you posted, but struggles a bit when
colonies overlap a lot. That will probably require a bit of manual
editing at the end, which should be relatively straight forward in the
ROI manager.

Hope this helps,
Volko


imageName=getTitle;
run("8-bit");

//find filter and crop image
run("Duplicate...", "TempImage");

setAutoThreshold("Triangle");
setOption("BlackBackground", true);
run("Convert to Mask");
run("Open");
run("Dilate");
run("Invert");
if(roiManager("count")>0){
     roiManager("Deselect");
     roiManager("Delete");
};
run("Analyze Particles...", "size=1000-Infinity circularity=0.5-1.00 add");
run("Set Measurements...", "area centroid bounding redirect=None
decimal=1");
run("Clear Results");
roiManager("Measure");
close();

diameter=minOf(getResult("Width",0),getResult("Height",0));
centreX=getResult("X",0)-diameter/2;
centreY=getResult("Y",0)-diameter/2;
selectWindow(imageName);
makeOval(centreX,centreY,diameter,diameter);
run("Crop");

//remove gridlines
run("Duplicate...", "TempImage");
run("Subtract Background...", "rolling=50");
setAutoThreshold("Triangle dark");
run("Convert to Mask");
run("Options...", "iterations=2 count=1 black do=Open");
run("Watershed");
run("Create Selection");
close();
selectWindow(imageName);
run("Restore Selection");
run("Clear Outside");

//detect colonies
run("Select None");
run("Duplicate...", "TempImage");
setAutoThreshold("MaxEntropy dark");
run("Convert to Mask");
run("Options...", "iterations=1 count=1 black do=Open");
run("Watershed");
if(roiManager("count")>0){
     roiManager("Deselect");
     roiManager("Delete");
};
run("Analyze Particles...", "add");
close();
selectWindow(imageName);
roiManager("Show All");



On 13/11/2015 15:16, MariaS wrote:

> <http://imagej.1557.x6.nabble.com/file/n5014946/petri_dish.jpg>
>
> Dear everybody,
>
> I am new to ImageJ and I am trying to automate the task of manually
> selecting a circular ROI.
>
> I have this kind of images and I want everytime ImageJ to automatically
> detect the inside membrane, which is not exactly in the same position in
> every image. Then I want to Clear the Outside, so I can work on the region I
> am interested in. I tried with the plugin Hough Circles, but it doesn't
> really work; when I try to use it ImageJ crashes and I am not sure if it
> could give me the result I want, since I cannot use it.
>
> It would be really helpful if somebody could give me some advice. Is there
> an available plugin which could perform this task?
>
> Thank you in advance.
> Maria
>
>
>
> --
> View this message in context: http://imagej.1557.x6.nabble.com/Automatically-detect-circular-ROI-tp5014946.html
> Sent from the ImageJ mailing list archive at Nabble.com.
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html

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

Colony_Counter.ijm (1K) Download Attachment