0

在此处输入图像描述我试图在图像上画一条红线,这是玻璃切片的显微镜图像。我已经可以找到边缘并在其中的一部分上画一条小线,但我无法沿着整个图像绘制它。

如果我有一组霍夫变换的线条,如何使这些线条更准确,因为它们在某些图像中并不总是在边缘,然后过滤它们以获得最高和最水平的线条,最后绘制它沿着图片?

在此处输入图像描述

rotI = imread('VHX_000006.jpg');

[PIC_X, PIC_Y] = size(rotI);

%% convert it to the gray scale
rotI = rgb2gray(rotI);

%Binarize grayscale the image by thresholding
BW = imbinarize(rotI); 
% complement the image (objects of interest must be white)
BW = ~BW; 
img = BW;

%% edge detection using canny flter to detect only the horizontal lines with the given threshold
BW = edge(img, 'canny', [0.6 0.8], 'horizontal');

%Hough Transform
[H,theta,rho] = hough(BW);

P = houghpeaks(H,5,'threshold',ceil(0.3*max(H(:))));

x = theta(P(:,2));
y = rho(P(:,1));
plot(x,y,'s','color','black');

lines = houghlines(BW,theta,rho,P,'FillGap',10000,'MinLength',70);

highestLine = [lines(1).point1; lines(1).point2];
figure, imshow(rotI), hold on
max_len = 0;
for k = 2:length(lines)
   firstLine = [lines(k - 1).point1; lines(k - 1).point2];
   plot(firstLine(:,1),firstLine(:,2),'LineWidth',0.0001,'Color','red');
   % Determine the endpoints of the longest line segment
   len = norm(lines(k).point1 - lines(k).point2);
   if ( len > max_len)
      max_len = len;
      xy_long = firstLine;
   end
end
4

0 回答 0