I have centroid of multiple areas of an image. I want to use those centroids to crop 288 by 288 regions around the centroid and then calculate the summed pixel area of the ORIGINAL IMAGE(non-binary image). I want to do this with a for loop so that I can have a vector or some output of summed pixel areas of my cropped image from ALL of my centroids.
Here is my the code I have written so far, but I am only getting the summed pixel area of one centroid still.
if trueloadedimage=originalimage;xCentroids=allCentroids(1:2:end); %already calculated x and y centroid locations from function regionprops
yCentroids=allCentroids(2:2:end);[size1,size2]=size(xCentroids);for k=1:1:size1 xmin=xCentroids(1,k); ymin=yCentroids(1,k); croppedimages=imcrop(loadedimage, [xmin ymin 288 288]); pixellevel=graythresh(croppedimages);endend
I am not sure if it is even possible to use the function "imcrop" in a for loop in this way? Do I need to keep the original in binary form to use it in a loop in this way?
Best Answer