creating image mask of 288 by 288 pixel from centroid location, threshold the image mask and out put summed pixel area

5 views (last 30 days)
Hi all,
I am very new to the image analyst world. I have an image that has had the centroids calculated ( ) 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=bwareaopen(binaryImage, 120);
for k=1:1:size1
crop=imcrop(binaryImage, [xmin ymin width height]);

Accepted Answer

Image Analyst
Image Analyst on 12 Aug 2016
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.
Image Analyst
Image Analyst on 17 Aug 2016
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.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!