0

How can i calculate the average of a certain area in an image using mat-lab? For example, if i have an intensity image with an area that is more alight and i want to know what is the average of the intensity there- how do i calculate it? I think i can find the coordinates of the alight area by using the 'impixelinfo' command. If there is another more efficient way to find the coordinates i will also be glad to know. After i know the coordinates how do i calculate the average of part of the image?

Maayan
  • 149
  • 1
  • 9
  • 2
    The most crude way would be to take the relevant pixels (area of your choosing) in the array format and find the mean of those by simply adding the "value" (could be saturation in grayscale, RGB etc.). Would something like this work? There's also plenty of functions that enable you to e.g. blur the image etc. so really depends what you need the average for. – Aleksander Lidtke Sep 08 '13 at 08:04
  • I don't need to blur the image. How can i take the relevant pixels and put it in an array? I'm familiar with the command improfile- this command returns the pixels of a line that i draw. If there is a similar 2-D command that will return an array of the pixels inside a form that i will draw that will be helpful. Is there any command like that? – Maayan Sep 08 '13 at 08:22
  • Well they are just entries in the array, I don't see what the problem would be. Perhaps this is something that you're looking for: http://stackoverflow.com/questions/12705817/understanding-region-of-interest-in-opencv-2-4 – Aleksander Lidtke Sep 08 '13 at 08:42
  • @Maayan: If you want the average of an area, (Gaussian) blurring is one of the most common and easiest ways to do this. – Junuxx Sep 08 '13 at 09:42

1 Answers1

1

You could use one of the imroi type functions in Matlab such as imfreehand

I = imread('cameraman.tif');
h = imshow(I);
e = imfreehand;
% now select area on image - do not close image

% this makes a mask from the area you just drew
BW = createMask(e);

% this takes the mean of pixel values in that area
I_mean =  mean(I(BW));

Alternatively, look into using regionprops, especially if there's likely to be more than one of these features in the image. Here, I'm finding points in the image above some threshold intensity and then using imdilate to pick out a small area around each of those points (presuming the points above the threshold are well separated, which may not be the case - if they are too close then imdilate will merge them into one area).

se = strel('disk',5);
BW = imdilate(I>thresh,se);
s = regionprops(BW, I, 'MeanIntensity');
nkjt
  • 7,825
  • 9
  • 22
  • 28