Question

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. It sounds simple but I can't figure out how.

Was it helpful?

Solution 2

Assuming img is a MxNx3 image, you can do it like this:

[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

OTHER TIPS

You can turn the axis box on to simulate a cube, and do a 3D scatter plot:

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])

enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top