creating image mask of 288 by 288 pixel from centroid location, threshold the image mask and out put summed pixel area
2 次查看(过去 30 天)
显示 更早的评论
Hi all,
I am very new to the image analyst world. I have an image that has had the centroids calculated ( http://www.mathworks.com/matlabcentral/answers/299323-finding-centroid-of-an-image-with-a-summed-pixel-area-greater-than-120-pixels-squared ) thanks Image Analyst!
So now with these centroid locations (in struct array), I would like to take a 288 pixel by 288 pixel region around the centroid origins. My goal is to find the pixel value of this region, which I believe I can do with Otsu's method (graythresh function).
My attempts to calculate the coordinates for imcrop function for all my centroids have been unsuccessful, so I thought I would reach out to the MATLAB professionals.
Any help is of course appreciated.
Here is my attempt:
binaryImage=imregionalmax(loadedimage)
binaryImage=bwareaopen(binaryImage, 120);
labeledImage=logical(binaryImage);
props=regionprops(labeledImage,'Centroid');
allCentroids=allCentroids[props.Centroid];
xCentroids=allCentroids(1:2:end);
yCentroids=allCentroids(2:2:end);
allCentorids=allCentroids';
[size1,size2]=size(allCentroids);
for k=1:1:size1
xmin=xCentroids(1,k);
ymin=yCentroids(1,k);
width=288;
height=288;
crop=imcrop(binaryImage, [xmin ymin width height]);
pixellevel=graythresh(crop)
end
end
0 个评论
采纳的回答
Image Analyst
2016-8-12
Not sure what "the centroid's origin" means, but it appears that you want the upper left centroid, and to take a box going 288 pixels down from that and 288 pixels over from that, regardless if other centroids are included in that cropping box. So to do that, you'd do (without any loop at all):
xmin = floor(min(xCentroids));
ymin = floor(min(yCentroids));
width = 288;
height = 288;
croppedImage = imcrop(binaryImage, [xmin, ymin, width, height]);
that gives you the sub-image (the pixel values) of this 288x288 square of the binary image. I have no idea what you mean by "find the pixel value of this region" and why you think graythresh() may help you. There is nothing to threshold - it's already a binary image! And besides, you already have the pixel values because they're in the array croppedImage, so I don't know why you think you need any additional operations to get them.
5 个评论
Image Analyst
2016-8-17
Heath, first you said "cropped images" and now you say "a subimage centered around these centroids" making it sound like there's just one subimage around all of the centroids. Which is it? And I'd like to know how you got these centroids in the first place. I mean, you have them already, right, before you place a box around each of them (or the whole group depending on how you answer my first question). A diagram illustrating what you want to do would really help. For example I don't know if you'll have a bunch of 288x288 boxes scattered around at random centroid locations, or if you'll have them perfectly tiled and adjacent to each other, or if there is just one around the centroid of the centroids, if in fact you even do have centroids in advance of the box-placing process.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!