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

1 visualización (últimos 30 días)
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");

Respuesta aceptada

DGM
DGM el 27 de Jul. de 2023
Editada: DGM el 27 de Jul. de 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))
  1 comentario
Adenine Koo
Adenine Koo el 27 de Jul. de 2023
Thank you so much! I do need to select the cells manually. I will try this now and update on how it goes!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Read, Write, and Modify Image en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by