Measure the average intensity of pixels in a specified area repeatedly in the same image

12 visualizzazioni (ultimi 30 giorni)
Hi
I'm trying to measure average intensity within specified locations repeatedly in the same image, and then iterate to do this over multiple images. I'm finding MATLAB can only handle so many cropped images at a time. There must be an easier way to do this. Here is what I have so far.
A = cat(2,B,Th); %Concatenate ROI array in form [X,Y,dX,dY] to create specified regions (1285x4x6) -> many regions
%Use ROI array to determine mean intensities of sensors
for j = 1:numframes
for a = 1:1285 %number of ROI per image -> can only be cut down by about 1/3 for future
c(:,:,a,j) = imcrop(z(:,:,j),A(a,:,j));
m = mean(mean(c(:,:,a,j)));
end
end
Is there another way to do this than with imcrop. It seems very inefficient. It is struggling with the first 6 images right now and I have to do this for 600 so I need a more efficient way.
Thanks

Risposte (3)

Sid Jhaveri
Sid Jhaveri il 3 Mar 2017
Hi Tim,
Instead of using 2 for-loops, try using vectorization . This should help improve the performance.

Image Analyst
Image Analyst il 3 Mar 2017
Do the ROI overlap or are they all separate? If they're all separate, you can do it once to make up a binary image with all the masks, then call regionprops() to get the mean of all regions at once.
And you don't need to store all your c arrays. You can simply overwrite it each time:
thisSubImage = imcrop(z(:,:,j),A(a,:,j));
m(a) = mean2(thisSubImage); % Compute the mean for this 2-D channel of z.

Tim Sanborn
Tim Sanborn il 8 Mar 2017
Hi guys,
Thank you very much for the responses. The ROI are all seperate but I need to keep the individual c arrays for future processing.
To update, I've come to realize the real problem is at a certain point (Image 7 for example) one of the 1285 centroids disappears from the picture. I believe this particular centroid is located at the edge of the image and (due to thermal expansion) is being moved out of frame. It starts barely in frame. Is there a way to tell regionprops to ignore all centroids near the edge of the image?
Tim
  1 Commento
Image Analyst
Image Analyst il 8 Mar 2017
There is no way a centroid can be outside the edges of the image. It might be outside of a blob, like the centroid of a fat C shape is in the center outside the C itself, but you can't have a centroid be outside the entire image itself.

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by