I'm trying to extract edge from an image. I used the following algorithm.Input image(e11) which is a 512 * 512 grayscale image is also given.
- Find the morphological gradient of input image(gradientim)
- Find the negative image of the gradient image(negativeim)
- Subtract original image from the closed image using bottom-hat transformations(bottomhatim).
- Compute average pixel of input image(AVG)
- Find the binary image based on AVG to smoothen the image.
- Find the largest connected region to find the larger objects(CC).
- Subtract largest region is from the smoothened image(edge).
The matlab code I'm written is given below
e11 = imread("lena.jpg");
e11= double(e11);
gradientim = imdilate(e11,se) - imerode(e11,se);
negativeim = imcomplement(gradientim);
bottomhatim = imclose(negativeim,se) - e11 ;
AVG = mean2(e11);
%-------Computing binary image--------
for i=1:(height)
for j=1:(width)
if(AVG > bottomhatim(i,j,:))
bottomhatim(i,j,:) = 1;
else
bottomhatim(i,j,:) = 0;
end
end
end
CC = bwconncomp(bottomhatim);
edge = bottomhatim - CC;
While doing step 7, Since the type of the connected component(CC) is 'struct' ,I'm getting an error as follows
"Undefined function 'minus' for input arguments of type 'struct'".
Is "bwconncomp" function can be used to find the largest connected region?Is there any alternate function for this?Please help me to correct this code.Thanks in advance.