How Can I detect a blurred line out of a low resolution image in Matlab
5 次查看(过去 30 天)
显示 更早的评论
This is an IR frame that comes from an IR video. I took this video from an orchard with an IR camera mounted on a drone. I need to find the white pipe in each of the frame. But I have to adjust the "houghpeaks" and "im2bw" level parameters every time to have the pipe detected in different frame. Also I need the white pipe to be detected as a continuous one from the left of the image all the way to the right side. But even if the pipe was detected, it has several blind spots due to the branches. It really took me forever to get this far, and don't have any ideas of how to finish this. The code I use is:
close all
clear
clc
% Read in image and the image info
I = imread('0003frame103.jpg');
info = imfinfo('0003frame103.jpg', 'jpg');
% Convert to binary image
Level = 0.57;
Bimage = im2bw(I,Level);
[H, T, R] = hough(Bimage);
figure, imshow(imadjust(rescale(H)),[],...
'XData',T,...
'YData',R,...
'InitialMagnification','fit');
xlabel('\theta (degrees)')
ylabel('\rho')
axis on
axis normal
hold on
colormap(gca,hot)
% Find the peaks in the Hough transform matrix, H, using the houghpeaks function.
P = houghpeaks(H,5,'threshold',ceil(0.3*max(H(:))));
% Superimpose a plot on the image of the transform that identifies the peaks.
x = T(P(:,2));
y = R(P(:,1));
plot(x,y,'s','color','black');
lines = houghlines(Bimage,T,R,P,'FillGap',5,'MinLength',7);
figure
imshowpair(I,Bimage,'montage'), hold on
max_len = 0;
for k = 1:length(lines)
xy = [lines(k).point1; lines(k).point2];
plot(xy(:,1),xy(:,2),'LineWidth',2,'Color','green');
% Plot beginnings and ends of lines
plot(xy(1,1),xy(1,2),'x','LineWidth',2,'Color','yellow');
plot(xy(2,1),xy(2,2),'x','LineWidth',2,'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 = xy;
end
end
% highlight the longest line segment
plot(xy_long(:,1),xy_long(:,2),'LineWidth',2,'Color','red');
And the image is attached.
Thank you so much for your time and help
0 个评论
回答(1 个)
Matt Sprague
2017-11-8
I was able to get good results on this image from using the horizontal components of the Sobel edge filter before inputting to your current workflow using the Hough transform. However I am doubtful that this particular code would be robust for the other images collected. Further adjustments to the threshold used in the "edge" command and filtering of the hough lines may be needed. More info on the edge can found be found through this link.
close all
clear
clc
% Read in image and the image info
I = imread('0004frame153.jpg');
I = I(:,:,1);
%Sobel Edge filter
BW = edge(I,'Sobel',0.3,'horizontal');
[H,theta,rho] = hough(BW);
P = houghpeaks(H,3,'threshold',ceil(0.3*max(H(:))));
x = theta(P(:,2));
y = rho(P(:,1));
lines = houghlines(BW,theta,rho,P,'FillGap',5,'MinLength',7);
imshow(BW)
figure, imshow(I), hold on
%Extract endpoints from individual hough lines
points = [];
for k = 1:length(lines)
points = [points; lines(k).point1; lines(k).point2];
end
% Fit overall line from individual lines from hough
x1 = 1:size(I,2);
p = polyfit(points(:,1),points(:,2),1);
y1 = polyval(p,x1);
plot(x1,y1,'r','LineWidth',3)
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!