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

3 views (last 30 days)
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)

Answers (1)

Walter Roberson
Walter Roberson on 13 Apr 2016
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.

Community Treasure Hunt

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

Start Hunting!