when i do segemtation on any image it return开发者_C百科s an image i-e binary image with representation of background and foreground. now if i want to use the background of an image only for any purpose..... how to do it..i mean after segmentation i got a binary image now how to identify (or take) the values of background only.???????
% Assume you have these variables:
% 'mask' - binary segmentation results, all 1's or 0's.
% 'img' - original image.
% 'bgImg' - Output, containing background only.
bgImg = zeros(size(img)); % Initialize to all zeros.
bg(mask) = img(mask); % Use logical indexing.
I'm assuming you have a grayscale image. When you have your segmented target as 1's and background as 0's then just do the element wise matrix multiplication to get target image. This is similar to masking. If you want background only, you can just do (1 - Binary image) and do similar multiplication with original image. Remember that this is element wise multiplication and not matrix multiplication.
If you want to measure statistics of foreground/background regions, an interesting choice would be regionprops
% img - variable containing original grey-scale image
% mask - binary mask (same size as img) with 0 - background 1 - foreground
% using regionprops to measure average intensity and weighted centroid,
% there are MANY more interesting properties ou can measure, use
% >> doc regionprops
% to discover them
st = regionprops( mask + 1, img, 'MeanIntensity', 'WeightedCentroid');
% get BG avg intensity:
fprintf(1, 'Avg intensity of background = %.2g\n', st(1).MeanIntensity );
精彩评论