Geoscience Reference
In-Depth Information
I5 = imsubtract(I3,I4);
imshow(I5,'XData',[0 ix],'YData',[0 iy])
title('Background')
h e function
im2bw
converts the background-free image
I4
to a binary
image
I6
by thresholding. If the threshold is 1.0 the image is all black,
corresponding to the pixel value of 0. If the threshold is 0.0 the image is all
white, corresponding to a pixel value of 1. We manually change the threshold
value until we get a reasonable result and i nd 0.2 to be a suitable threshold.
I6 = im2bw(I4,0.2);
imshow(I6,'XData',[0 ix],'YData',[0 iy])
title('Binary Image')
We next eliminate objects in
I6
that overlap the image border, since they are
actually larger than shown in the image and will result in false estimates. We
eliminate these using
imclearborder
and generate image
I7
.
I7 = imclearborder(I6);
himage1 = imshow(I6,'XData',[0 ix],'YData',[0 iy]); hold on
set(himage1, 'AlphaData', 0.7);
himage2 = imshow(imsubtract(I6,I7),'XData',[0 ix],'YData',[0 iy]);
set(himage2, 'AlphaData', 0.4);
title('Image Border'), hold off
We then trace the boundaries using
bwboundaries
in a binary image where
non-zero pixels belong to an object and zero pixels are background. By
default, the function also traces the boundaries of holes in the
I7
image.
We therefore choose the option
noholes
to suppress the tracing of the holes.
Function
label2grb
converts the label matrix
L
resulting from
bwboundaries
to an RGB image. We use the colormap
jet
, the zerocolor
w
for
white
,
and the color order
shuffle
(which simply shul es the colors of
jet
in a
pseudorandom manner).
[B,L] = bwboundaries(I7,'noholes');
imshow(label2rgb(L,@jet,'w','shuffle'),...
'XData',[0 ix],'YData',[0 iy])
title('Define Objects')
h e function
bwlabeln
is used to obtain the number of connected objects
found in the binary image. h e integer 8 dei nes the desired connectivity,
which can be either 4 or 8 in two-dimensional neighborhoods. h e elements
of
L
are integer values greater than or equal to 0. h e pixels labeled 0 are the
background. h e pixels labeled 1 make up one object, the pixels labeled 2
make up a second object, and so on.
[labeled,numObjects] = bwlabeln(I7,8);