direction of flow lines in an image
7 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi,
I have a 2D image or image data. I want to find the average direction of flow lines with respect to horizontal. how can i do that.
Attached is the iamge I generated by using
imgradient
red lines I draw to show the approximate flow of lines in the image and \theta is the average angle , which I want to determine.
0 commentaires
Réponse acceptée
yanqi liu
le 12 Oct 2021
sir,please check the follow code to get some information
clc; clear all; close all;
im = imread('https://ww2.mathworks.cn/matlabcentral/answers/uploaded_files/764756/untitled.jpg');
jm = rgb2lab(im);
s = mat2gray(jm(:,:,2));
bw = im2bw(s);
bw = bwareafilt(bw,1);
bw2 = imopen(bw, strel('line', 19, 0));
bw(bw2) = 0;
bw = bwareafilt(bw,1);
[H,T,R] = hough(bw);
P = houghpeaks(H,5,'threshold',ceil(0.3*max(H(:))));
lines = houghlines(bw,T,R,P,'FillGap',5,'MinLength',7);
max_len = 0;
line_r = [];
for k = 1:length(lines)
xy = [lines(k).point1; lines(k).point2];
% 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;
line_r = lines(k);
end
end
figure; imshow(im); hold on;
plot(xy_long(:,1),xy_long(:,2),'LineWidth',2,'Color','cyan');
title(sprintf('theta=%.1f°', 90-line_r.theta));
6 commentaires
Plus de réponses (1)
yanqi liu
le 12 Oct 2021
sir,please check the follow code to get some information
clc; clear all; close all;
img = imread('cameraman.tif');
[Gx,Gy] = imgradientxy(img);
[Gmag,Gdir] = imgradient(Gx,Gy);
mk = zeros(16,16);
mk(8:9,:) = 1;
mk = logical(mk);
ms = mk;
% rotae theta
mk = imrotate(mk, 30);
mk = bwmorph(mk,'thin',inf);
% find direction
res = imfilter(double(Gdir), double(mk), 'replicate');
res = res > max(res(:))*0.5;
figure;
subplot(2, 2, 1); imshow(mat2gray(Gdir)); title('origin image');
subplot(2, 2, 2); imshow(mat2gray(ms)); title('h base filter');
subplot(2, 2, 3); imshow(mat2gray(mk)); title('theta filter');
subplot(2, 2, 4); imshow(mat2gray(res)); title('result');
2 commentaires
Voir également
Catégories
En savoir plus sur Image Segmentation and Analysis dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!