Detecting a specific line in an image

28 views (last 30 days)
paloma paleo
paloma paleo on 6 Nov 2020
Answered: paloma paleo on 10 Nov 2020
Hello,
I have several images and I need to detect a profile that it changes on time. The images are grey colours and the constrast is not great in the area that I want to detect the edge.
I have tried several ways and methods (e.g. thresholder filter, using all methods with 'edge', changing the LUT in the image etc etc).
Any suggestions?
I have included an example of the image and the line that I would like to detect. The line is clear to my eye but I cannot get a script to detect it.
I would really appreciate your help!
Thanks

Answers (2)

Pranav Verma
Pranav Verma on 9 Nov 2020
Hi Paloma,
You can try using the basic image segmentation method for the line detection if the methods you specified are not working for you.
The image processing toolbox in MATLAB has specific functionalities for image segmentation. Please refer to the below link for the same:
Thanks
  1 Comment
paloma paleo
paloma paleo on 9 Nov 2020
I have already tried using the different methods for image segmentation but it doesnt work. I am not getting the line that I am looking for.

Sign in to comment.


paloma paleo
paloma paleo on 10 Nov 2020
I have tried several ways (see code below) but I am not getting any good results.
close all
% Read in image and the image info
I = imread('Img000000.tif');
I = I(:,:,1);
option=2; %option 1 sobel
%option 2 segmentation
if option==1
%Sobel Edge filter
BW = edge(I,'Sobel',0,'both');
imtool(BW)
[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',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)
end
if option==2
% option 2.1
% level = graythresh(I);
%
% BW = imbinarize(I,level);
% imshowpair(I,BW,'montage')
% option 2.2
% level = multithresh(I);
% seg_I = imquantize(I,level);
% figure
% imshow(seg_I,[])
% option 2.3
% [counts,x] = imhist(I,16);
% stem(x,counts)
% % figure(1), plot(x,counts)
% T = otsuthresh(counts);
% BW = imbinarize(I,T);
% figure
% imshow(BW)
% option 2.4 - best
% T = adaptthresh(I, 0.75);
% BW = imbinarize(I,T);
% figure
% imshowpair(I, BW, 'montage')
% option 2.5
%
% J = grayconnected(I,184,30);%choose the x,y values of the seed intesity
% imshow(labeloverlay(I,J))
% option 2.6
%
% mask = zeros(size(I));
% %mask(25:end-25,25:end-25) = 1;
% mask(:,60:end-850) = 1;
% %imshow(mask)
% %title('Initial Contour Location')
% bw = activecontour(I,mask,50);
% imshow(bw)
% title('Segmented Image, 300 Iterations')
% option 2.7
%
% RGB=I;
% L = superpixels(RGB,500);
%
% figure(1)
% imshow(I)
%
% %roi = drawrectangle %provides the coord info of the rectangular draw using
% %the mouse
% f = drawrectangle(gca,'Position',[65 0 120 1020],'Color','g');
%
% foreground = createMask(f,RGB);
% b1 = drawrectangle(gca,'Position',[217.1442 8.7460 203.9004 1.0158e+03],'Color','r');
% b2 = drawrectangle(gca,'Position',[0.5000 2.7489 75.7130 1.0218e+03],'Color','r');
% background = createMask(b1,RGB) + createMask(b2,RGB);
%
% BW = lazysnapping(RGB,L,foreground,background);
% imshow(labeloverlay(RGB,BW,'Colormap',[0 1 0]))
%option 2.8
%mask(:,60:end-850) = 1
% mask = false(size(I));
% mask(30,170) = true;
%
%
% W = graydiffweight(I, mask, 'GrayDifferenceCutoff',1000);
%
% thresh = 0.009;
% [BW, D] = imsegfmm(W, mask, thresh);
% figure
% imshow(BW)
% title('Segmented Image')
%
%
%
%
%
% imshow(I)
% title('Original Image')
% seedpointR = 72;
% seedpointC = 100;
% W = graydiffweight(I, seedpointC, seedpointR,'GrayDifferenceCutoff',250);
% figure (23), imshow(log(W))
% thresh = 0.0001;
% [BW, D] = imsegfmm(W, mask, thresh);
% figure (55)
% imshow(BW)
% title('Segmented Image')
% Ifil=medfilt2(BW, [5 5]);
% imtool(Ifil)
end

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by