Can you use an image gradient to complete a quiver plot?
5 ビュー (過去 30 日間)
古いコメントを表示
Is it possible to plot a quiver plot of a gradient, such as the one attached, showing the magnitude and the direction of the change in pixel intensity?
Could the resulting plot then be used to create a boundary between the two extreme color pixel values? ![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/291929/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/291929/image.png)
2 件のコメント
採用された回答
darova
2020 年 5 月 12 日
Try this madness
I0 = imread('image.png');
I1 = rgb2gray(I0); % convert to gray/intensity
I1 = double(I1); % conver integer to double
[m,n] = size(I1);
[u,v] = gradient(I1,1,1); % calculate gradient (dx and dy)
[x,y] = ndgrid(1:m,1:n); % x,y grid
ii = 1:100:numel(x);
quiver(x(ii),y(ii),u(ii),v(ii))
2 件のコメント
Flint Marko
2021 年 8 月 12 日
編集済み: Flint Marko
2021 年 8 月 12 日
I used this code on a gradient image and saw pretty good results. I did change one bit as I wanted to display the arrows on every pixel:
ii = 1:1:numel(x); % to add an arrow for every pixel
I am confused as to what exactly the direction of the arows means. In general they are pointing from darkest(0) to lightest pixel(up to 255) in their vicinity, with the size of the arrow corresponding to how drastic the change is. For example a black pixel(0) neighboring a white pixel(255) would have a larger arrow than a black pixel(0) neighboring a grey pixel(~50).
With the code you provided however, the angles of the arrows are not pointing directly at the center of the brightest neighboring pixel as you might expect, at times it will be in a horizontal directions. Still, in general the arrows point in the desired direction, but I am unsure how you would use this to quantify a gradient. For example how can the data extracted from [Gmag,Gdir] be used to show that there is a difinitive difference between an image with a gradient in a clear direction vs an image with no gradient and no clear direction? Additionally, can we sum the vectors to show one big arrow showing the angle in which the gradient is generally headed?
darova
2021 年 8 月 14 日
Sorry, didn't test the code. I made a mistake (see comments). I made some changes to the code, mainly removed large values in gradients (appears because of boundary)
I0 = imread('image.png');
I1 = rgb2gray(I0); % convert to gray/intensity
I1 = double(I1); % conver integer to double
[m,n] = size(I1);
[u,v] = gradient(I1); % calculate gradient (dx and dy)
[y,x] = ndgrid(1:m,1:n); % x,y grid (made a mistake before)
ind = find( abs(u) < 10 & abs(v) < 10 ); % choose only small values
ii = ind(1:1500:numel(ind)); % reduce quivers
quiver(x(ii),y(ii),u(ii),v(ii))
axis equal
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Vector Fields についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!