Elliptical crop of an image to get average pixel value within the region
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
DGM
le 27 Juil 2023
Modifié(e) : DGM
le 27 Juil 2023
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))
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Read, Write, and Modify Image dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!