getting statistics from within a mask within an image

5 次查看(过去 30 天)
We have an image that represents data that only makes sense when it is analyzed in numerical format.
Specifically, the data needs to be analyzed as a function of radius as shown below
Im interested specifically in hte max and min values within each of the defined areas with respect to the center point.
Ive been looking at a few examples online and it seems this should work when you pull the data from a mask.
However, the issue is that I seem to be getting values that are not realistic.
this is what I am doing
clear
img = double(imread('img121.jpg'));; %no filtration
img = -(0.0316*img) +8.3; % we did this as we cant calibeate the film, we scan the same film over and over and it changes by 80pixels
img = imrotate(img, 90);
img = imgaussfilt(img ,1.5);
figure, imagesc(img )
axis image
height2 = 3.6;
caxis([0 height2])
colorbar
title(' ')
impixelinfo
%# make sure the image doesn't disappear if we plot something else
hold on
%https://www.mathworks.com/matlabcentral/answers/1931825-how-to-get-pixel-value-inside-a-circle
%below looks like what we want
%https://www.mathworks.com/matlabcentral/answers/1931825-how-to-get-pixel-value-inside-a-circle
%# define points (in matrix coordinates)
%3"
cpx = 2050;
cpy = 2020;
inchlist = [12,10.5,9,7.5,6,4.5];
%draw lines on heel axis
for n=1:size(inchlist,2)
inch= inchlist(n)/4;
hcirc = drawcircle('Center',[2050,2020],'Radius',inch*590,'StripeColor','red');
mask1 = hcirc.createMask;
maxval = (max(img(mask1)));
minval = (min(img(mask1)));
uniformity = maxval/minval
% p1 = [cpy-100,cpx+inch*590];
end
uniformity = 6.8965
uniformity = 5.3893
uniformity = 5.3893
uniformity = 5.3893
uniformity = 3.7992
uniformity = 1.9168
Even after getting this max and min value, I will need to remove 10 to get rid of noise. Extra credit if you can point me to a soluton for that too.
thank you
  3 个评论

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2024-8-16
移动:Walter Roberson 2024-8-16
To find out where the maximum of the masked image is:
IdxImg = reshape(1:numel(img), size(img));
masked_image_idx = IdxImg(mask1);
[max_value, max_idx] = max(img(mask1));
index_of_max = masked_image_idx(max_idx);
[MaxRow, MaxColumn, MaxPage] = ind2sub(size(img), index_of_max);
This works by creating an indexing image the same size as the original image, but containing 1, 2, 3, ... all the way up to the maximum array element number. Then you extract the portion of the indexing image under the mask, to get a vector of the element numbers covered by the mask. Then take the max() of the masked image, getting out the (linear) index of the maximum element. Use the linear index of the maximum element to index the vector of indexing array elements selected by the max, getting out the linear index of the array element in the original image. Then convert the linear index back to subscripts if necessary.
  1 个评论
JM
JM 2024-8-19
编辑:JM 2024-8-19
Walter,
I appreciate the help with this function to get the max and min values. I admit I dont totaly understand the masking.
Using the coordinates returned from the code you provided, Im still not able to see the pixel values being retuned as the max and min that make sense with the orignal image. There is something funny going on.
I have attached the orignal image that is being run with the script.
from scanning through the areas defined by the mask, I would expect each region to produce a max and min that produce uniformity (max/min) that is around 1 to 2. However, we are getting values of like 8 which is not possible. Yes, there are noise points in there but nothing to produce large values like this.
thank you again.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by