You are here : matlabImage Processingimseggeodesic

imseggeodesic() - Image Processing

L = imseggeodesic(RGB,BW1,BW2) segments
the input image RGB, which must be a valid RGB
image, returning a segmented binary image with segment labels specified
by label matrix L. BW1 and BW2 are
binary images that specify the location of the initial seed regions,
called scribbles, for the two regions (foreground
and background). imseggeodesic uses the scribbles
specified in BW1 and BW2 as
representative samples for computing the statistics for their respective
regions, which it then uses in segmentation. The scribbles specified
by BW1 and BW2 (regions
that are logical true) should not overlap. The underlying algorithm
uses the statistics estimated over the regions marked by the scribbles
for segmentation. The greater the number of  pixels marked by scribbles,
the more accurate the estimation of the region statistics, which typically
leads to more accurate segmentation. Therefore, it is a good practice
to provide as many scribbles as possible. Typically, provide at least
a few hundred pixels as scribbles for each region.exampleL = imseggeodesic(RGB,BW1,BW2,BW3) segments
the input image RGB, returning a segmented image
with three segments (trinary segmentation) with the region labels
specified by label matrix L. BW1, BW2,
and BW3 are binary images that specify the location
of the initial seed regions or scribbles for the three regions. The
scribbles specified by BW1, BW2,
and BW3 (regions that are logical true) should
not overlap.example[L,P] =
imseggeodesic(___) returns the probability
for each pixel belonging to each of the labels in matrix P.example[L, P] = imseggeodesic(___,Name,Value,...) segments
the image using name-value pairs to control aspects of segmentation.
Parameter names can be abbreviated.


Syntax

L = imseggeodesic(RGB,BW1,BW2) exampleL = imseggeodesic(RGB,BW1,BW2,BW3) example[L,P] =
imseggeodesic(___) example[L, P] = imseggeodesic(___,Name,Value,...) example


Example

Segment Image into Two Regions Using Color InformationOpen This Example
Read image into workspace and display it.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')


Segment Image into Three Regions Using Color InformationOpen This Example
Read image into the workspace and display it.RGB = imread('yellowlily.jpg');
imshow(RGB,'InitialMagnification', 50)
hold on

Creates scribbles for three regions. Note that you can specify the scribbles interactively using tools such as roipoly, imfreehand, imrect, impoly, and imellipse. Region 1 is the yellow flower. Region 2 is the green leaves. Region 3 is the background.region1 = [350 700 425 120]; % [x y w h] format
BW1 = false(size(RGB,1),size(RGB,2));
BW1(region1(2):region1(2)+region1(4),region1(1):region1(1)+region1(3)) = true;

region2 = [800 1124 120 230];
BW2 = false(size(RGB,1),size(RGB,2));
BW2(region2(2):region2(2)+region2(4),region2(1):region2(1)+region2(3)) = true;

region3 = [20 1320 480 200; 1010 290 180 240];
BW3 = false(size(RGB,1),size(RGB,2));
BW3(region3(1,2):region3(1,2)+region3(1,4),region3(1,1):region3(1,1)+region3(1,3)) = true;
BW3(region3(2,2):region3(2,2)+region3(2,4),region3(2,1):region3(2,1)+region3(2,3)) = true;
Display the seed regions.visboundaries(BW1,'Color','r');
visboundaries(BW2,'Color','g');
visboundaries(BW3,'Color','b');

Segment the image.[L,P] = imseggeodesic(RGB,BW1,BW2,BW3, 'AdaptiveChannelWeighting', true);
Display results.figure
imshow(label2rgb(L),'InitialMagnification', 50)
title('Segmented image with three regions')

figure
imshow(P(:,:,2),'InitialMagnification', 50)
title('Probability that a pixel belongs to region/label 2')


Output / Return Value


Limitations


Alternatives / See Also


Reference