how to get RGB color?
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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;
0 commentaires
Réponses (2)
Image Analyst
le 9 Mai 2014
Modifié(e) : Image Analyst
le 9 Mai 2014
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 commentaires
Image Analyst
le 11 Mai 2014
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.
Oliver Woodford
le 9 Mai 2014
Modifié(e) : Oliver Woodford
le 10 Mai 2014
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 commentaires
Voir également
Catégories
En savoir plus sur Blue dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!