MATLAB: Making a histogram and limiting gaussian filter to a boundary

histogramImage Processing Toolbox

hi, i saw ur responses on mathworks central. please help me on this. i am implementing the attached paper. please look at figure no. 2 and figure 4, how one person can make the histogram of that image. the number black pixels are much more in number but they are not reflected in histogram. and second question is if i find the breast boundary, can i limit my gaussian filter to work only that boundary ?
Thanks in advance
Bilal

Best Answer

You can either take the histogram of the whole image and suppress the bin at gray level 0:
[pixelCounts, grayLevels] = imhist(grayImage);\
pixelCounts(1) = 0; % Zero out the black bin.
or you can have a mask and take the histogram of pixels only within the mask:
[pixelCounts, grayLevels] = imhist(grayImage(mask));
To make filter work only within mask you have to decide what you want to do at the boundary. Do you want it to consider pixels outside the boundary and just mask off the result?
filteredImage = imfilter(grayImage, kernel); % Filter whole image

filteredImage(mask) = 0; % Mask off result.
Or do you want to consider pixels outside as zero?
grayImage(~mask) = 0; % Zero outside mask.
filteredImage = imfilter(grayImage, kernel); % Filter whole image
Neither is right or wrong - it just depends on how you want to handle it.