How do I get RGB color? Or what I got using 'pcolor()' can be considered to be as RGB?
Vx = V_x1 + V_x2;
Vy = V_y1 + V_y2;
ang = atan2(Vy, Vx);
pcolor(x, y, ang);
hold on;

답변 (2개)

Image Analyst
Image Analyst 2014년 5월 9일
편집: Image Analyst 2014년 5월 9일

0 개 추천

pcolor() does not return an RGB image. It displays one. If you display a matrix though, pcolor chops off one row and one column so you're better off using image(). I never use pcolor for displaying images for that reason. I don't really know what you're doing because you didn't attach a screenshot. If you have certain kinds of data that pcolor is meant for, it might be fine, but I find it very deceptive for displaying 2D arrays of numbers.
If you do want what pcolor displays as an RGB image, I think you can use getframe().

댓글 수: 5

JMS
JMS 2014년 5월 9일
I am representing the directions of the field using the colors. The strength of the field is adapted by the size of the arrows. It does give all the RGB colors or at least 'look like' but I was not sure and you mentioned it doesn't. So, better to find another way.
Image Analyst
Image Analyst 2014년 5월 9일
What I was mentioning was that if you have a 26 by 26 array, pcolor() will display only 25 by 25 of it. I'm still not sure I understand your question about how to "get" the rgb image from pcolor. Explain exactly what "get" means to you: (1) display as an image, or (2) get the image into an array (a variable). For (2), you can use getframe().
Star Strider
Star Strider 2014년 5월 10일
From the documentation of pcolor:
  • MATLAB® creates a pseudocolor plot using each set of four adjacent points in C to define a surface rectangle (i.e., cell).
  • The number of vertex colors for pcolor(C) is the same as the number of cells for image(C). pcolor differs from image in that pcolor(C) specifies the colors of vertices, which are scaled to fit the colormap; changing the axes clim property changes this color mapping. image(C) specifies the colors of cells and directly indexes into the colormap without scaling. Additionally, pcolor(X,Y,C) can produce parametric grids, which is not possible with image .
Yeah, I always thought that was extremely confusing. For example let's look at this code where you send a 3 by 3 array into pcolor and it plots tiles in a 2 by 2 array:
clc;
m = [1 2 3;
4, 5, 6;
7, 8, 9]
pcolor(m) % Show 2 by 2 tiles.
cm = gray(9)
colormap(cm);
fr = getframe(gca);
theImage = fr.cdata;
[rows, columns, numberOfColorChannels] = size(theImage)
upperLeftColor = double(theImage(floor(rows/4), floor(columns/4), 1))/256
upperRightColor = double(theImage(floor(rows/4), floor(3*columns/4), 1))/256
lowerLeftColor = double(theImage(floor(3*rows/4), floor(columns/4), 1))/256
lowerRightColor = double(theImage(floor(3*rows/4), floor(3*columns/4), 1))/256
Be aware that the image is upside down with respect to the matrix.
Now, you can see that the lower left quadrant is supposed to be defined by a surface going between corner vertices that have values 1, 2, 4, and 5. So the surface is a tilted, warped surface. Wouldn't the color in that patch change as it goes from the lower values to the higher values? No, it's a single color? Okay, but which color does it use? Evidently it uses the color defined by the lower left vertex only, which for the lower left would be 1, and so the color is 0. The other vertices with values 2, 4, and 5 are apparently ignored when choosing a color. It's confusing. But I see a lot of people using pcolor() to display images.
JMS
JMS 2014년 5월 11일
Ok, can we just forget about pcolor() command because I do not have much information about what you are talking about, sorry. Suppose we have the below equations '
x1 = -1; y1 = 0;x2 = 0; y2 = 0;
[x,y] = meshgrid(-5: .2: 5, -5: .2: 5);
V_x1 = ((y-y1)./((x-x1).^2+(y-y1).^2));
V_y1 = ((x-x1)./((x-x1).^2+(y-y1).^2));
V_x2 = (-(y-y2)./((x-x2).^2+(y-y2).^2));
V_y2 = (-(x-x2)./((x-x2).^2+(y-y2).^2));
Vx = V_x1 + V_x2;
Vy = V_y1 + V_y2;
quiver(x, y, Vx, Vy);
hold on
ang = atan2(Vy, Vx);
?
?
"
And I need to have 'RGB' image depending on the angle. How do I do that? I hope this is clear.

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

Oliver Woodford
Oliver Woodford 2014년 5월 9일
편집: Oliver Woodford 2014년 5월 10일

0 개 추천

You can use the sc toolbox, from the File Exchange. In your case, try:
im = sc(ang, 'hsv');
However, there is also a colormap implemented for 2D vector flow fields, which encodes both direction and magnitude. Try:
im = sc(cat(3, Vx, Vy), 'flow');

댓글 수: 4

JMS
JMS 2014년 5월 9일
Sorry but it doesn't work after importing the 'im = sc(ang, 'hsv');' or ' im = sc(cat(3, Vx, Vy), 'flow');' unless I have to do something with SC toolbox which I am not sure what does it mean. I guess it is already built in matlab.
Oliver Woodford
Oliver Woodford 2014년 5월 10일
It's available on the file exchange.
JMS
JMS 2014년 5월 12일
Dear Oliver Woodford..I clicked on 'Get from GitHub' and downloaded the zip file to the "..\MATLAB" folder and unzipped and modified the simple code to be:
'
x1 = -1; y1 = 0;x2 = 0; y2 = 0;
[x,y] = meshgrid(-5: .2: 5, -5: .2: 5);
V_x1 = ((y-y1)./((x-x1).^2+(y-y1).^2));
V_y1 = ((x-x1)./((x-x1).^2+(y-y1).^2));
V_x2 = (-(y-y2)./((x-x2).^2+(y-y2).^2));
V_y2 = (-(x-x2)./((x-x2).^2+(y-y2).^2));
Vx = V_x1 + V_x2;
Vy = V_y1 + V_y2;
quiver(x, y, Vx, Vy);
hold on
ang = atan2(Vy, Vx);
im = sc(cat(3, Vx, Vy), 'flow');
'
But it doesn't work. Could you please tell what is wrong? Still say undefined function 'SC'.. Even I used 'im = sc(cat(3, Vx, Vy), 'flow');'. Thank you.
Oliver Woodford
Oliver Woodford 2014년 5월 12일
The toolbox needs to be on your MATLAB search path .

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

카테고리

도움말 센터File Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

질문:

JMS
2014년 5월 9일

댓글:

2014년 5월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by