282 8 IMAGE PROCESSING
that 1 % of the data is saturated at low and high intensities. is increases
the contrast of the new image
I3.
I3 = imadjust(I2);
imshow(I3,'XData',[0 ix],'YData',[0 iy])
title('Adjusted Intensity Values')
We next determine the background of the image I3, i. e., basically the
texture of the black foil upon which the grains are located. e function
imopen(im,se) determines objects in an image im below a certain pixel
size and a at structuring element
se such as a disk with a radius of 3 pixels
generated by the function
strel. We then produce a background-free im-
age,
I4.
I4 = imopen(I3,strel('disk',1));
imshow(I4,'XData',[0 ix],'YData',[0 iy])
title('No Background')
We substract the background-free image I4 from the original grayscale im-
age
I3 to observe the background I5 that has been eliminated.
I5 = imsubtract(I3,I4);
imshow(I5,'XData',[0 ix],'YData',[0 iy])
title('Background')
e function im2bw converts the background-free image I4 to a binary im-
age
I6 by thresholding. If the threshold is 1.0 the image is all black, corre-
sponding to the pixel value of 0. If the threshold is 0.0 the image is all white,
equivalent to a pixel value of 1. We manually change the threshold value
until we get a reasonable result and 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 whereas zero pixels are back-