Elliptical crop of an image to get average pixel value within the region

4 ビュー (過去 30 日間)
Adenine Koo
Adenine Koo 2023 年 7 月 27 日
コメント済み: Adenine Koo 2023 年 7 月 27 日
Hi all
I wish to analyse the average pixel value of an elliptical region of interest (cell nucleus) in my image. I first read the image into a matrix of pixel value, and for now I used imcrop to crop a rectagular region of interest and get an average pixel value of this region. However, because the region of my interest is circular/elliptical, so cropping in rectangular decreases the average pixel value because of the extra background included. I am wondering if there is a way to crop/just calculate the average pixel value of the region in ellipse/circle instead?
Here is my current code:
imshow(refImage);
[nucleus, nucleusSpec] = imcrop(gcf);
nucleusSpec = round(nucleusSpec);
nucleusXCoor = [nucleusSpec(1), (nucleusSpec(1) + nucleusSpec(3))];
nucleusYCoor = [nucleusSpec(2); (nucleusSpec(2) + nucleusSpec(4))];
ROI1Area = refImage(nucleusYCoor(1):nucleusYCoor(2), nucleusXCoor(1):nucleusXCoor(2));
ROI1 = mean(ROI1Area, "all");

採用された回答

DGM
DGM 2023 年 7 月 27 日
編集済み: DGM 2023 年 7 月 27 日
If you're manually placing things, you can use the ROI tools such as drawellipse() and drawcircle() to create a mask.
% an example image
inpict = imread('tire.tif');
% create ROI object by manually placing an ellipse
imshow(inpict); % show the image
ROI = drawellipse(gca); % interactively place the ellipse
input('Press ENTER when finished'); % wait until user is done adjusting things
% create a mask from the ROI object
mk = createMask(ROI);
% find average pixel value in the region (assuming image is single-channel)
avgpx = mean(inpict(mk))
  1 件のコメント
Adenine Koo
Adenine Koo 2023 年 7 月 27 日
Thank you so much! I do need to select the cells manually. I will try this now and update on how it goes!

サインインしてコメントする。

その他の回答 (0 件)

製品


リリース

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by