I'm trying to make a 3d plot of the pixel intensity in an image, however I cannot seem to make my code work

2 次查看(过去 30 天)
So I want to be able to import an image (of stars in the sky), and make a 3D plot of the pixel intensity, so that the stars are easily identifiable as "spikes" in the surface.
I've got this code that other's says should work:
J = imread('IMG_1442.jpg');
I = imresize(J,.2)
[x y]=meshgrid(1:size(I,1), 1:size(I,2));
scatter3(x(:),y(:),I(:),15,I(:),'filled');
axis tight; colormap gray
But whenever I run it I get the following error:
Error using scatter3 (line 94)
X, Y and Z must be vectors of the same length.
Error in image_test (line 4)
scatter3(x(:),y(:),I(:),15,I(:),'filled');
(The reason I resize the image is because it is extremely large. I've attached a compressed version of the file so that you can see what I'm working with)

回答(1 个)

Walter Roberson
Walter Roberson 2016-4-13
JPEG images are almost always RGB images, even when they look like black and white. The number of pixel components in an RGB image is 3 times larger than you are expecting. You should convert to grayscale before doing the scatter plot.

类别

Help CenterFile Exchange 中查找有关 Lighting, Transparency, and Shading 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by