フィルターのクリア

Can you use an image gradient to complete a quiver plot?

1 回表示 (過去 30 日間)
Pranaya Kansakar
Pranaya Kansakar 2020 年 5 月 10 日
コメント済み: darova 2021 年 8 月 14 日
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?
  2 件のコメント
darova
darova 2020 年 5 月 10 日
Yes it's possible. Try gradient
Pranaya Kansakar
Pranaya Kansakar 2020 年 5 月 12 日
編集済み: Pranaya Kansakar 2020 年 5 月 12 日
This was obviously the first thing I did but your suggestions came out as nonsenscial images.
I put the code:
sc = rgb2gray(sc);
>> [x y] = imgradient(sc);
>> figure;
imshowpair(x,y,'montage')
And the resulting image was as follows:
Surely, there is a better way to accurately extract the gradient representing the increase of pixel values with respect to distance?
something along the lines of https://en.wikipedia.org/wiki/Image_gradient#/media/File:Gradient2.svg

サインインしてコメントする。

採用された回答

darova
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
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
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 件)

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by