MATLAB: How to sub-sample a portion of an image – using an ellipse shape sample.

image analysisimage samplingsub-sampling

Im trying to subsample a matrix, where my sample shape is an ellipse. My matrix is a 2100 pixels X 500 pixels, and i want to create an ellipse at the center-top of this matrix. Not just drew an ellipse but average the values inside it. What would you suggest? Thank you in advance. In the following code i did it for a rectangular and i want to have an ellipse instead:
% create the elongated dichromatic image PatchWidth=700; background=zeros(2100,500); background=background+180; background((2100/2)-round(PatchWidth/2):((2100/2)+(round(PatchWidth/2))),1:500)=30; background_fig=imshow(uint8(background)); hold on rectangle('Position',[200 1 100 RectWidth],'EdgeColor','r')

Best Answer

Then extract all the values inside the ellipse and get their average like this:
averageValueInsideEllipse = mean(yourImage(ellipticalMask));