現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
How to visualize gradient data using arrows.
12 ビュー (過去 30 日間)
古いコメントを表示
I need help with the quiver function. I want to visualize the magnitude and angle data i have gotten from a block processing, with arrows in each block just like the (b) image below. Please how can i do that?

2 件のコメント
Ameer Hamza
2020 年 4 月 26 日
Can you share the information about the arrows directions in a .mat file?
Fego Etese
2020 年 4 月 26 日
I have attached the matab files and my matlab workspace. I am using the gray image to get the orientation.
I am getting the average magnitude and direction for each block of size 16 x 16 and after getting these in the OrientationEstimation file with the variables coherence and angle, i will like to draw the arrows in the direction of the angle with the length as the coherence value in each block.
採用された回答
Ameer Hamza
2020 年 4 月 26 日
編集済み: Ameer Hamza
2020 年 4 月 26 日
According to the coherence and angle variable you shared. You can make the quiver plot using this
dX = coherence.*cosd(angle);
dY = coherence.*sind(angle);
x = 1:size(dX,2);
y = 1:size(dX,1);
[X, Y] = meshgrid(x, y);
quiver(X,Y,dX,dY);
axis tight
But it does not look like the image you shared. Are you sure that the formula used to calculate coherence and angle is correctly implemented?
28 件のコメント
Fego Etese
2020 年 4 月 26 日
編集済み: Fego Etese
2020 年 4 月 26 日
Yes i believe i implemented it correctly. The result of the quiver is very different from the one i have above. The thing is the size of the coherence matrix is smaller than the actual image, because of the block processing, is it possible to plot an arrow in each block on the image representing the magnitude and direction of that block? maybe using block processing?
Fego Etese
2020 年 4 月 26 日
Looking at the code again, you're converting the magnitude and angle back to cartesian coordinates before passing into the quiver function, i thought in the quiver function the parameter u, the third parameter is the magnitude while the 4th parameter is the angle, or am i getting this all wrong?
Ameer Hamza
2020 年 4 月 26 日
I was doubtful because if you look, the outer edges of the coherence matrix have several 1s, which shows that the arrow magnitude will be largest. However, your image suggests that there are no arrows near the edges.
quiver function takes the x and y components of the vector field. You can see examples of the quiver.
Fego Etese
2020 年 4 月 26 日
Sorry, the 1s are caused by me, i did an if statement to check if all the pixels in a block are white and if they are i gave the block a coherence value of 1 and an angle of 0, that was to stop the error of NaN i was getting during the block processing.
So does that mean the quiver function uses the cartesian values of the vector field?
Ameer Hamza
2020 年 4 月 26 日
So should those 1s in coherence matrix be treated as 0s?
Yes, the quiver take the cartesian components of the vector field.
Fego Etese
2020 年 4 月 26 日
Yes, like they are not actually relevant as later on i will be segmenting the image before applying the orientatino estimation and those parts will be cut out, i just wanted to implement the orientation estimation first before i do the segmentation.
Please can you explain what the parameters of the quiver means? Like what does the x,y,u,v parameters take when passing arguments to the quiver in the context of gadients. I have tried to read the docs but i still dont understand.
Thanks
Ameer Hamza
2020 年 4 月 26 日
x and y define the grid of on which quiver will draw the vector field. Quiver works like this.
It takes an x-y coordinate, say
(x(i,j), y(i,j))
It goes to corresponding locations u and v matrices
(u(i,j), v(i,j))
and it draws a vector at location
and the x-y magnitude of vector is given by
. It iterates over all the locations in the matrix (x,y) and draws the vector with the corresponding location components in (u,v)


Fego Etese
2020 年 4 月 26 日
If i understand correctly, shouldn't u and v be the magnitude and angle of the arrow quiver draws, this has me confused? also, will it make sense if in the block processing, i get the coordinate of the center pixel of each block and use that to draw the vectors on the original gray image?
Please what do you use the meshgrid to do?
Fego Etese
2020 年 4 月 26 日
編集済み: Fego Etese
2020 年 4 月 26 日
I just did some research and i think that the values for the coherence and direction of a block are to be applied to every pixel in that block when using the quiver, because the calculation for the coherence and direction is to get the average directional field of the image so as to get the orientation of the ridges in the gray image.
Ameer Hamza
2020 年 4 月 27 日
No, u, and v are the x and y components of the vector. This makes it easy to extend it to a higher dimension, such as quiver3. In 3D, using angles to specify the vector direction will be very cumbersome.
I think when you write the getAvgCoherence and getAvgAngle, you can return a block of 16x16 as output so that the dimension between input and output remains the same.
Fego Etese
2020 年 4 月 27 日
I have used this approach just now but the arrows drawn are too much in the image i would like to draw one big arrow or a line in each box using the angle and coherence. I am setting the coherence to 1 so it will be the same size all through the image. Please how can i do this? Something like this below

Ameer Hamza
2020 年 4 月 28 日
quiver() does not output an image, so there is no direct way to make the output of quiver of the same size as the input image. Also, I guess, the issue right now is the calculation of arrow direction at the edges. The coherence value is maximum at the edges, which makes the arrows very large. The arrow in the middle is smaller in comparison. You need to have a way to filter out the non-required coherence values.
Fego Etese
2020 年 4 月 28 日
編集済み: Fego Etese
2020 年 4 月 28 日
I have filtered out the non-required coherence values by setting the coherence to be zero at the edges so it doesn't draw any arrows there but only in places that have a black pixel. And I set the rest to 1 to have uniform size. I understand that quiver doesn't output an image but at least is there a way to draw one big arrow in each block instead of pixel by pixel even if it's not using quiver? Because I'm starting to doubt whether quiver can draw this. Or should I increase the scale of the arrow and draw the arrow at the middle pixel of each block?
Ameer Hamza
2020 年 4 月 28 日
Does the function in blockproc return a single-pixel or a grid of 16x16? If it returns a single-pixel then the code in my answer should plot one array for a block.
Fego Etese
2020 年 4 月 28 日
At the moment it returns a grid of 16 by 16. Please how can I make it return a single pixel and still find that pixel in the quiver? Will this single pixel also be the center pixel in the block? Also please, when you say plot one array what do you mean?
Ameer Hamza
2020 年 4 月 28 日
I guess in the original code, you attached in your question. The function getAvgAngle and the other function take a block of 16x16 and return a single value. Right?
Fego Etese
2020 年 4 月 28 日
Yes that was what the original code outputted, but the single value is the averaged value for the whole block
Fego Etese
2020 年 4 月 28 日
Yes, that's what I want but I want to plot it over the original image size, not on its own so that the arrows are in each block that was processed, maybe in the middle of each block.
Ameer Hamza
2020 年 4 月 28 日
Ok. I get it now. You want to plot it over the original image?? Apart from that, are you able to get correct arrows if you plot it on regular MATLAB axes using quiver?
Fego Etese
2020 年 4 月 28 日
編集済み: Fego Etese
2020 年 4 月 28 日
Since I changed the coherence values for white pixels to 0 I haven't tried plotting again on Matlab axes. I will try that once I can access my laptop. But the last time I tried it with the code you gave me it didn't work as expected. I'm still trying to check my implementation whether it's correct.
Ameer Hamza
2020 年 4 月 28 日
I guess that if you are able to plot it correctly on MATLAB axes(), then you can also be able to plot it on the image. So, you first need to check, if the direction and size of arrows looks correct on axes().
Fego Etese
2020 年 4 月 28 日
I am now able to plot it at the center pixel of each block, I looked for the index of the center element in each block and set that center element to the coherence and angle values while leaving the rest of the elements in the block at zero so that when quiver plays the arrows it only plots at the center element and it plots on the axes of the original image and then I scaled the size of the arrow up by 15 so the arrows are bigger. Though unfortunately it seems like what I implemented did not work as the arrows aren't following the black ridges in the image. I guess that has to do with the algorithm I implemented right?
Ameer Hamza
2020 年 4 月 28 日
Are you able to create a small matrix (1value for 16x15 block)? If yes, then you don't need to increase its size to be the same as your image manually. I found that the quiver function has an option to overlay a smaller matrix on a larger image. If you can attach the image and the smaller matrix with coherence and angle information, I can suggest a solution.
Fego Etese
2020 年 4 月 29 日
Hi, Ameer, I'm sorry for being gone for a while, I've been trying to do some research into my implementation and i found out that I actually missed something there in it.
Firstly, I forgot to divide the final angle calculation by 2 and secondly I was plotting the wrong data. I was plotting the ridge valley direction instead of the gradient direction. And thirdly i hadn't actually finished the implementation.
Please now I am stuck at one point of the implementation, in this paper i don't understand the Eq 10 about the Guassian filter, I have only one value for each direction from Eq 8 and 9, but it asks me to apply a 2D gaussian filter to the image. I am assuming that I am to create two matrices of zeros same size as the block, fill the two block with the two values i have individually, and do a gaussian filter on both matrices using imgaussfilt, and then pick only one value from each of the filtered matrices. the problem here is that i don't understand that EQ10. Please am I correct in my understanding so far? Thank you 

Ameer Hamza
2020 年 4 月 30 日
I am not sure about these equations. I don't have a strong background in image processing, and understanding it will require some preliminary knowledge.
Fego Etese
2020 年 4 月 30 日
Oh, I understand. Thank you so much. I'll try to look into it more. Maybe raise a new question about it. When I'm done with understanding and implementing it I'll come back to sort out the quiver issue.
I really appreciuate your time.
Thanks
Ameer Hamza
2020 年 4 月 30 日
Yes, that will be good. You are likely to get an answer on this issue from someone else. You can then comment here again when this issue is resolved.
その他の回答 (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!エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
アジア太平洋地域
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)