[英]How to display an rgb image in a RGB colour cube in MATLAB
So I have a RGB image and I want to display it in a RGB colour cube with its pixels as points in the colour cube. 所以我有一个RGB图像,我希望将其显示在RGB颜色立方体中,其像素为颜色立方体中的点。 It sounds simple but I can't figure out how. 这听起来很简单,但我无法弄清楚如何。
You can turn the axis box on to simulate a cube, and do a 3D scatter plot: 您可以打开轴框以模拟立方体,并执行3D散点图:
I = imread('peppers.png');
vRGB = reshape(I,[],3);
plot3(vRGB(:,1),vRGB(:,2),vRGB(:,3),'.','MarkerSize',0.5)
set(gca,'Box','on')
xlabel('red'); ylabel('green'); zlabel('blue');
xlim([0 255]); ylim([0 255]); zlim([0 255])
Assuming img
is a MxNx3 image, you can do it like this: 假设img
是MxNx3图像,你可以这样做:
[M, N, ~] = size(img);
plot3(...
reshape(img(:,:,1), 1, M * N), ...
reshape(img(:,:,2), 1, M * N), ...
reshape(img(:,:,3), 1, M * N), '.')
xlabel('Red'), ylabel('Green'), zlabel('Blue')
grid on
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.