![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/179786/image.png)
How do I isolate lines at a certain angle in an image.
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
N/A
am 7 Mär. 2018
Kommentiert: Akira Agata
am 12 Mär. 2018
Good day, I am trying to isolate the lines at an angle of 45 degrees in an image. The isolated lines should be the only lines present or occurring in the output file. Below is a link of a sample .jpg file
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/171053/image.jpeg)
0 Kommentare
Akzeptierte Antwort
Akira Agata
am 8 Mär. 2018
Bearbeitet: Akira Agata
am 8 Mär. 2018
Same as previous post, you can utilize regionprops function, like:
% Read your image and binarize
I = imread('5159-15B front_imgJ-macro.jpg');
I = rgb2gray(I);
BW = imbinarize(I);
% Apply regionprops function
s = regionprops(~BW,{'MajorAxisLength','MinorAxisLength','Orientation','PixelIdxList'});
s = struct2table(s);
% Extract the regions which satisfies both the following conditions:
% (1) (Minor axis length)/(Major axis length) <= 20%
% (2) Angle with horizontal line is +/-45 degree with 10 degree margine
idx =...
(s.MinorAxisLength ./ s.MajorAxisLength <= 0.2) &...
(abs(abs(s.Orientation)-45) <= 10);
s = s(idx,:);
% Show the result
BWout = true(size(BW));
for kk = 1:height(s)
BWout(s.PixelIdxList{kk}) = false;
end
figure
imshow(BWout)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/179786/image.png)
2 Kommentare
Akira Agata
am 12 Mär. 2018
If you want to extract lines with an angle of 10~80 and -80~-10 degree, please change the condition of idx in the script as follows:
idx =...
(s.MinorAxisLength ./ s.MajorAxisLength <= 0.2) &...
(((10 <= s.Orientation) & (s.Orientation <= 80)) |...
((-80 <= s.Orientation) & (s.Orientation <= -10)));
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!