How do you use Planet Imagery in MATLAB?

Can anyone direct me to a tutorial or example on how to utilize MATLAB when working with Planet Imagery?

I have a particular scene from Planet with multiple files (Tiff, JSON, etc) Whats the best way to upload and combine in MATLAB using Digital Image Processing.  

Thank you 





  • Hi Michael,

    you can use the geotiffread function to read your images into the MATLAB workspace.

        Example: [A,R] = geotiffread('2141729_1156105_2019-02-22_1027_BGRN_Analytic.tif');

    A is the image as an M-by-N-by-4 array. The 4 layers are the different bands of the satellite image, i.e. blue, green, red and near-infrared. Sometimes the fourth layer is a data mask. This depends on the type of asset you downloaded.


    R is a MATLAB spatial referencing object. R can be used to display the image georeferenced to map coordinates with the mapshow function.

        Example: mapshow(A(:,:,1),R)

    This displays the first layer (blue band) of A georeferenced to the map coordinates stored in R.


    Alternatively, you can use imread and imshow to read and display the image file. However, if you use these functions, the spatial information is lost.


    You can now access the image data as with any numeric MATLAB array. 

        Example: Red = A(:,:,3);

    This extracts the third layer (red band) and assings it to the new variable Red.


    Combine different bands to an RGB image using the cat function.

        Example: RGB = cat(3,Red,Green,Blue);


    To read the JSON files, use the fileread function and the jsondecode function.

    fileread returns the contents of a file as a character array. jsondecode converts the character array to a MATLAB structure array.

        Example: metadata = jsondecode(fileread('2141729_1156105_2019-02-22_1027_metadata.json'));

  • Hi, I have been trying to use geotiffread to read planet images but I get the error "Error using geotiffinfo>readinfo (line 278)
    Multiple images exist in the file and their sizes are different". I have used imread and it works, however I do not know why neither geotiffread or geotiffinfo work. Do you know what can I do?

  • Hi Eli,

    Yeah, I had that problem before. May I ask which Matlab version you're using? I got this error with version R2018b, but they fixed it in R2019a, I think. So I'd suggest you upgrade to R2019a and see if it works. EDIT: That doesn't work. See the comments below.

    If this doesn't work or you're already using version R2019a, there is a workaround where you modify the geotiffinfo function by adding two lines of code. You can read this blog post by Yu Jiang for detailed instructions.

    I hope this helps. Let me know if it worked.

  • Hi Lukas, thanks for your answer. I tried with Matlab R2018a and R2018b. Unfortunately we still do not have R2019a license. When I use imread, I have to specify the image index, for example, imread('Name.tif',1) or imread('Name.tif',2) and in each options it reads a NxNx4 matrix with different NxN resolution for each index. Basically each TIFF image has 16 images grouped by 4. What I did is to batch clip in ArcMap all the images to the desired location and then read the TIFF again in Matlab. It worked. geotiffread loaded correctly the clipped TIFF images. Cheers.

  • Sorry, I think I got something mixed up.

    As you said, the error occurs because the scene is stored as 4 different images with different resolutions in one tif file. I've just tried to load one of these files and got the same error even with MATLAB version R2019a.

    Seems like you get these GeoTIFFs with multiple images when you download scenes as a whole. The reason I don't get this error anymore is not because of MATLAB version R2019a, but because I use Planet's server-side clipping service. It's a tool of the new Orders v2 API that clips the scene to a dersired extent before downloading it. The output of this clipping operation is only one image in one tif file. You can load these tif files with geotiffread without any problems. I guess the result is similar to your solution with ArcMap.

    I also tried Yu Jiang's workaround where you force MATLAB to read only the first image of a multi-image GeoTIFF, and it works perfectly. I think that's the best solution to your problem :) Cheers, Lukas

  • I'm trying to use MATLAB R2019b to read in some planetscope GeoTIFFS.  I'm using some code that works with the same filetype from the NASA Worldview server. Everything works fine except for the colormap. I typically convert the RGB images to indexed color images and this doesn't seem to work.  Any suggestions as to what could be going wrong would be appreciated. 



Please sign in to leave a comment.

Didn't find what you were looking for?

New post