getting statistics from within a mask within an image

조회 수: 5 (최근 30일)
JM
JM 2024년 8월 16일
이동: Walter Roberson 2024년 8월 19일
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
JM
JM 2024년 8월 19일
이동: Walter Roberson 2024년 8월 19일
Anyone have any thoughts?
JM
JM 2024년 8월 19일
이동: Walter Roberson 2024년 8월 19일
all set

댓글을 달려면 로그인하십시오.

채택된 답변

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