Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

LaTeX Placing greyscale .jpg images into a matrix

  1. Jul 25, 2016 #1

    Larry Gopnik

    User Avatar
    Gold Member

    Hi, I hope someone can help me!

    I could not find a solution online of which could help me. My problem:

    I have imagecubes - they are a "cube" of 10 images of the same place of a photo, one at 400nm, one at 450nm etc etc.

    I need to upload these into matlab so I can then analyse the intensities at certain places in certain wavelengths. The best way I have thought of doing this is to place it into a 3d matrix of size 1550x1000x10 (where 1550x1000 are the size of each image) (if there is a better way of doing this I would be glad to hear them)

    Code:
    Code (Text):
    %-----------------------------%
    %----IMAGE CUBE------%
    %-----------------------------%
    sizex = 1550;        
    sizey = 1000;

    imageslice = 10;                %amount of slices the image cube is made of
    cube=zeros(sizex,sizey,imageslice);
    cubedir = 'C:\proc';
    ab = [1 2 3 4 5 6 7 8 9 10];
    for ij = 1:imageslice
     
       slice = ab(ij);
        slice1 = 1;
        slice2 = slice-slice1;
        slicenumber = int2str(slice2);
        filepath=[cubedir, '1_190716.f' slicenumber '.0.0.jpg'];
        fidr = imread(filepath,'r','l');
        cube{:,:,ij} = fread(fidr,[sizex,sizey],'uint8');
     
     
    end
    I'm getting the error:

    Code (Text):
    Error using readjpg
    Too many input arguments.

    Error in imread (line 415)
        [X, map] = feval(fmt_s.read, filename, extraArgs{:});
     
    I've looked online and the people who normally have this error are using tiff files. Where am I going wrong?!

    Thank you

    EDIT:

    I now have a different error.

    After contemplation I saw that maybe MatLab thinks the files are .tiff files, therefore I have changed the filetypes and hence the code to:

    Code (Text):
    %code code code

       slice = ab(ij);
        slice1 = 1;
        slice2 = slice-slice1;
        slicenumber = int2str(slice2);
        filepath=[cubedir, '_190716.f' slicenumber '.0.0.tiff'];
        fidr = Tiff('open',filepath,'r','l');
        cube(:,:,ij) = fread(fidr,[sizex,sizey],'uint8');
     
    %more code
    and I am now getting the error :

    Error using Tiff
    Too many input arguments.

    Error in Build_1 (line 107)
    fidr = Tiff('open',filepath,'r','l');
     
    Last edited: Jul 25, 2016
  2. jcsd
  3. Jul 25, 2016 #2
    I have a hyperspectral app that uses 30 wavelength PNG images. Using a 3D image is fine - just depends on what you want to do and how you want to do it. Or you might just process the images one image at a time without building a 3-D image in advance.

    You should use imread(), not Tiff() if they're jpg images. However imread() does not take string arguments 'r' and 'l' as far as I can tell from looking at the help. Just what do you think those arguments were supposed to be for? Try it giving just the filename and not those other two input arguments.
     
  4. Jul 26, 2016 #3

    Larry Gopnik

    User Avatar
    Gold Member

    I had talked to the person who had created the jpgs and they said that they used no compression at all in them so it was possible that the images were being treated like Tiffs hence the edit.

    As for the other arguments in the line - I had used the 'r', 'l' as that's what I used when uploading some .raw files earlier on in my program (I have never done image analysis before in matlab so the upload of many jpgs into a matrix is all new to me) so I just assumed that I'd need that for imread too - what a silly error!


    Thank you
     
  5. Jul 26, 2016 #4
    Larry, there is an uncompressed jpeg option. The format is jpeg2000 with an extension of j2k. Type imformats on the command line to see what formats your version of MATLAB can read in.

    To see if it's compressed, see what numel(rgbImage) is - that's how many pixels in all color channels - and then multiply by the number of bytes - 1 for uint8 and 2 for uint16. Then see how many bytes it is on disk with Windows File Manager or something. If it's uncompressed, then they will be the same number of bytes.

    Anyway, did imread() work once you took out the other two arguments?
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted



Similar Discussions: Placing greyscale .jpg images into a matrix
  1. Images in Latex (Replies: 16)

Loading...