我有以下图像,我在其上应用了双边滤波并将其从原始图像中减去
是否可以如图所示勾勒出玻璃缺陷
应用霍夫后,我得到以下结果并不完美:/
我的matlab代码:
im = imread('C:\Users\SUJIT\Desktop\image003.jpg');
im=rgb2gray(im);
h = fspecial('gaussian', size(im), 1.0);
g = imfilter(im, h);
im=im2double(g);
im=imadjust(im);
imgauss = imfilter(im, fspecial('gaussian',[7 7], 6),'conv');
imbi = bilateralfilter(im, [5 5], 3, 3);
imbi= im - imbi;
imshow(imbi,[]); title('Bilateral Filted Image');
I = imcrop(imbi, [30 30 450 350]);
J = imfilter(I, fspecial('gaussian', [17 17], 5), 'symmetric');
BW = edge(J, 'canny');
%# Hough Transform and show matrix
[H T R] = hough(BW);
imshow(imadjust(mat2gray(H)), [], 'XData',T, 'YData',R, ...
'InitialMagnification','fit')
xlabel('\theta (degrees)'), ylabel('\rho')
axis on, axis normal, hold on
colormap(hot), colorbar
%# detect peaks
P = houghpeaks(H, 10);
plot(T(P(:,2)), R(P(:,1)), 'gs', 'LineWidth',2);
%# detect lines and overlay on top of image
lines = houghlines(BW, T, R, P);
figure, imshow(I), hold on
for k = 1:length(lines)
xy = [lines(k).point1; lines(k).point2];
plot(xy(:,1), xy(:,2), 'g.-', 'LineWidth',2);
end
hold off
请帮助我在这里做错了吗?