Elliptical crop of an image to get average pixel value within the region
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Adenine Koo
am 27 Jul. 2023
Kommentiert: Adenine Koo
am 27 Jul. 2023
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 Kommentare
Akzeptierte Antwort
DGM
am 27 Jul. 2023
Bearbeitet: DGM
am 27 Jul. 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))
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Read, Write, and Modify Image finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!