In this example, we shall see how to use the disk structuring element from strel
, to have a better masking result for the middle rock of our holiday picture. To focus on our task, we will first crop the area we are mostly interested in. Assuming we have cleared our workspace using clear all
(MATLAB's command to clear all the variables), we follow these steps:
Read our colored image, convert it to grayscale, and crop the area containing the middle rock:
>> img = imread('3rocks.jpg'); >> rock = imcrop(rgb2gray(img));
Threshold the cropped image using the same threshold as before (
30
) and show the result side-by-side with the original:>> mask1 = rock < 30; >> subplot(1,2,1),imshow(rock),title('Original image') >> subplot(1,2,2),imshow(mask1),title('Initial mask')
Perform image cleaning, using the
imerode
function:>> mask2 = imerode(mask1,ones(2));
Make the structuring element for this rock, which will be the top...