Elliptical crop of an image to get average pixel value within the region
1 次查看(过去 30 天)
显示 更早的评论
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");
0 个评论
采纳的回答
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))
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Read, Write, and Modify Image 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!