필터 지우기
필터 지우기

direction of flow lines in an image

조회 수: 7 (최근 30일)
Abhishek Saini
Abhishek Saini 2021년 10월 12일
댓글: yanqi liu 2021년 10월 12일
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.

채택된 답변

yanqi liu
yanqi liu 2021년 10월 12일
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
Abhishek Saini
Abhishek Saini 2021년 10월 12일
thank you very much for a great answer. Are these things in the book. Is there English version of the book available?
yanqi liu
yanqi liu 2021년 10월 12일
sir,thankyou
sorry,the book has not English version
but,we can also discuss

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

yanqi liu
yanqi liu 2021년 10월 12일
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
Abhishek Saini
Abhishek Saini 2021년 10월 12일
Thanks yanqi liu for the response. But I donot understand the concept behind this. Why did you use
mk = imrotate(mk, 30);
Whatis the work of theta filter? My question is to find the angle of flow lines with respect to (w.r.t.) horizintal or vertical.
If you rotate the original image, the final results are still same, but it should change w.r.t. image angular direction
yanqi liu
yanqi liu 2021년 10월 12일
sorry,sir,i made a mistake

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Geometric Transformation and Image Registration에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by