The centroids of objects in an image have been found. It has then been cropped to a certain area. IS it possible to tell if more than one centroid is in a cropped image?

3 visualizaciones (últimos 30 días)
I have the centroids of all the objects of an image. I have than cropped a 288 by 288 pixel area around the images (the size of the area is to try and isolate one centroid uniformly). Is it possible to tell if I have more than one centroid within my cropped image.
Here is the code I have to find the centroid and crop it. I am using Otsu's method (graythresh the im2bw) to threshold because it is predetermined method I am suppose to use, even though I know there is better ways. Code at the beginning to take out all objects with less than 120 pixels connection is there as well just fyi.
The overall goal is to individually isolate the object that each centroid is on and to isolate it and find the area of it, after thresholding. Perhaps there is a better way.
if true
tic;
load image=originalimage;
binaryimage1=imregionalmax(loadimage);
binaryimage2=bwareaopen(binaryimage1,120);
labeledimage=bwlabel(binaryimage2);
props=regionprops(binaryimage2,'Centroid);
allCentroids=[props.Centroid];
xcentroids=allCentroids(1:2:end);
ycentroids=allCentroids(2:2:end);
numberofobjects=size(props);
for m=1:numberofobjects
xmin=xcentroids(m);
ymin=ycentroids(m);
cropthat=imcrop(loadimage, [xmin-144, ymin-144, 288, 288]);
pixellevel=graythresh(cropthat);
levelbw=im2bw(cropthat,pixellevel);
regionprops2=regionprops(levelbw,'area');
end

Respuesta aceptada

Image Analyst
Image Analyst el 19 de Ag. de 2016
Upload your image so we can see what this strange algorithm is doing. I say strange because it depends on getting a binary image from regional max but only if the regional max is 120 pixels in area or more. This happens only for large perfectly flat plateaus.
  7 comentarios
Image Analyst
Image Analyst el 30 de Ag. de 2016
First of all, what you did is not what they did. Secondly what they did is not that efficient and has some useless things in it.
They did not take a 120x120 pixel image around each local max. They took a 120 micron by 120 micron region. How many pixels this is depends on the magnification, but it's not going to be 120 pixels unless you have exactly 1 pixel per micron.
Then they take the region around each max, however one of their cells may have more than one local max in it (like I already said) so they may analyze all or a portion of a cell more than once. This will require you to have an accumulator binary image because you may only get part of the cell in each window. If you did get the whole cell then you may analyze it twice. Let's say your blob was a dumbbell with a bright max spot on each end. If the 120x120 field of view (FOV) encompassed the whole dumbell, you'd get the mask there twice because it does the 120x120 local region once at each end. If the 120x120 region was only big enough to get one end of the dumbbell, then one box would get one end and the other box would get the other end and you'd have to OR those two together into your accumulator image to record/save masks from both box locations.
Then they say that they do Otsu on a box and iterate it until they get a foreground area that is as close as possible to some "target cell size" that they defined in advance. Well, that's inefficient. No need to do Otsu and then iterate to "home in on" the final threshold. If you require that the foreground size (# pixels above threshold) is some number (I think they said 500 pixels or something), then you can simply use cumsum() on the histogram and find out where it first reaches or exceeds the target cell size. And you're not doing that (adjusting the original Ostu threshold guess). They say they did that, but like I said, iterating to find the final threshold (that will produce a foreground area that equals the TCS) will get you there but it's a complicated indirect way of getting the threshold, and probably slower as well.
Krispy Scripts
Krispy Scripts el 30 de Ag. de 2016
OK, thank you. They did 50 microns which converted to 120 pixels, but that is what I was confused on is finding regional max did not make sense because I thought there was most likely multiple regional max. I also did not think they were thresholding correctly. Thank you for looking at this.

Iniciar sesión para comentar.

Más respuestas (2)

Walter Roberson
Walter Roberson el 18 de Ag. de 2016
  2 comentarios
Krispy Scripts
Krispy Scripts el 18 de Ag. de 2016
Would it be more appropriate and efficient to just use regionprops after thresholding to find the area of the objects?
Walter Roberson
Walter Roberson el 18 de Ag. de 2016
That will not tell you whether you have more than one centroid in your cropped region. You are cropping relative to each centroid, and the only reason that might generate less than (288 x 288 x number of centroids) total area would be if one of the centroids happens to be less than 144 from an edge.
With your current code you are extracting a constant size around each centroid and that constant size might happen to include other centroids as well, but those centroids will also have their own centered extracted images.
If you want to crop in a way that if two centroids are closer together than 288 that the crops are merged, then that is a different task.

Iniciar sesión para comentar.


Krispy Scripts
Krispy Scripts el 19 de Ag. de 2016
Here is the attached image. I am basically trying to individually find the area, perimeter, circularity (ECD in image analyst's tutorials). So perhaps I am going about this all wrong with this code.
Any feedback or advice on how to analyze this would be so appreciated!

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by