www.gusucode.com > images 案例代码 matlab源码程序 > images/SegmentImageIntoTwoRegionsUsingColorInformationExample.m
%% Segment Image into Two Regions Using Color Information % %% % Read image into workspace and display it. % Copyright 2015 The MathWorks, Inc. RGB = imread('yellowlily.jpg'); imshow(RGB,'InitialMagnification',50) hold on %% % Specify the initial seed regions or "scribbles" for the foreground % object, in the form |[left_topR left_topC bottom_rightR bottom_rightC]|. bbox1 = [700 350 820 775]; BW1 = false(size(RGB,1),size(RGB,2)); BW1(bbox1(1):bbox1(3),bbox1(2):bbox1(4)) = true; %% % Specify the initial seed regions or "scribbles" for the background. bbox2 = [1230 90 1420 1000]; BW2 = false(size(RGB,1),size(RGB,2)); BW2(bbox2(1):bbox2(3),bbox2(2):bbox2(4)) = true; %% % Display seed regions. The foreground is in red and the background is % blue. visboundaries(BW1,'Color','r'); visboundaries(BW2,'Color','b'); %% % Segment the image. [L,P] = imseggeodesic(RGB,BW1,BW2); %% % Display results. figure imshow(label2rgb(L),'InitialMagnification', 50) title('Segmented image') figure imshow(P(:,:,1),'InitialMagnification', 50) title('Probability that a pixel belongs to the foreground')