이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
How to visualize gradient data using arrows.
조회 수: 7 (최근 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
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에서 Image Processing Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 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 (한국어)