Matlab - crop image based on foreground-background segmentation -


i have rgb image read matrix 3 dimensions, img, , have binary mask represents segmentation of image, mask.

how can crop image based on binary mask in matlab? tried select pixels marked binary mask resulted image not have original colors.

centralpoints = find(mask > 0); denoisedimage = zeros(424, 424, 3); slice1 = zeros(424, 424); origslice = img(:, :, 1); slice1(centralpoints) = origslice(centralpoints); slice2 = zeros(424, 424); origslice = img(:, :, 2); slice2(centralpoints) = origslice(centralpoints); slice3 = zeros(424, 424); origslice = img(:, :, 3); slice3(centralpoints) = origslice(centralpoints);  denoisedimage(:, :, 1) = slice1; denoisedimage(:, :, 2) = slice2; denoisedimage(:, :, 3) = slice3; 

this code. img original image, centralpoints coordinates of foreground pixels , denoisedimage represents cropped matrix.

however, denoisedimage no maintain colors of original image inside cropped region. foreground pixels not form rectangular region, however, form 1 connected component.

have tried

denoisedimage = bsxfun( @times, im2double(img), mask > 0 ); 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -