MATLAB: Mammogram image processing: How to find the mean pixel values of a ROI

image processingImage Processing Toolboxmammogramwatershed segmentation

Hello,
I'm analyzing mammogram images. I've applied watershed segmentation on my preprocessed images, where it identified the region of interest (ROI) and have superimposed it on my preprocessed image. Now I'd like to extract the pixel values of this ROI from the preprocessed image, and then find the mean pixel value from this matrix. May someone assist me on this? I've tried to find the perimeter of the ROI then export the coordinates, but then I'm stuck, may someone advise me how to proceed from there?
Thanks.
Below is my code for the Watershed Segmentation:
'b' is the preprocessed image.
hy = fspecial('sobel');
hx = hy';
Iy = imfilter(double(b), hy, 'replicate');
Ix = imfilter(double(b), hx, 'replicate');
gradmag = sqrt(Ix.^2 + Iy.^2);
L = watershed(gradmag);
Lrgb = label2rgb(L);
se = strel('disk', 20);
Io = imopen(b, se);
Ie = imerode(b, se);
Iobr = imreconstruct(Ie, b);
Ioc = imclose(Io, se);
Iobrd = imdilate(Iobr, se);
Iobrcbr = imreconstruct(imcomplement(Iobrd), imcomplement(Iobr));
Iobrcbr = imcomplement(Iobrcbr);
fgm = imregionalmax(Iobrcbr);
figure
imshow(fgm), title('Regional maxima of opening-closing by reconstruction (fgm)'),axis on,impixelinfo;
I2 = b;
I2(fgm) = 255;
%figure



%imshow(I2), title('Regional maxima superimposed on original image (I2)');axis on;
se2 = strel(ones(5,5));
fgm2 = imclose(fgm, se2);
fgm3 = imerode(fgm2, se2);
fgm4 = bwareaopen(fgm3, 3500);
I3 = b;
I3(fgm4) = 255;
%figure
%imshow(I3)
%title('Modified regional maxima superimposed on original image (fgm4)');
bw = im2bw(Iobrcbr, graythresh(Iobrcbr));
%figure
%imshow(bw), title('Thresholded opening-closing by reconstruction (bw)');
D = bwdist(bw);
DL = watershed(D);
bgm = DL == 0;
%figure
%imshow(bgm), title('Watershed ridge lines (bgm)');
gradmag2 = imimposemin(gradmag, bgm | fgm4);
L = watershed(gradmag2);
I4 = b;
I4(imdilate(L == 0, ones(3, 3)) | bgm | fgm4) = 255;
figure
imshow(I4)
title('Markers and object boundaries superimposed on original image (I4)');axis on;impixelinfo;
Thank you! =)
Jon

Best Answer

It is not really clear which is your ROI. It looks like it might be the region you assign 255 to in I4. If so, then
ROI = imdilate(L == 0, ones(3, 3)) | bgm | fgm4;
I4(ROI) = 255;
ROImean = mean(b(ROI));