ガラス片の顕微鏡画像である画像に赤い線を引こうとしています。すでにエッジを見つけて、その一部に小さな線を引くことはできましたが、画像全体に沿って描くことはできませんでした。
ハフ変換からの線のグループがある場合、これらの線をより正確にする方法は、一部の画像では常に端にあるとは限らないためです。次にそれらをフィルタリングして、最も高く最も水平な線を取得し、最後に描画します写真の通りですか?
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