LaTeX Placing greyscale .jpg images into a matrix

  • Thread starter Thread starter Larry Gopnik
  • Start date Start date
  • Tags Tags
    Images Matrix
Click For Summary
SUMMARY

The discussion focuses on the process of loading greyscale .jpg images into a 3D matrix in MATLAB for analysis. The user initially encounters errors with the imread function due to incorrect input arguments and later attempts to use the Tiff function, which also results in errors. Key recommendations include using imread() without additional string arguments and verifying the image format with imformats. The user is advised to check the compression of the images to ensure compatibility with MATLAB.

PREREQUISITES
  • Familiarity with MATLAB programming
  • Understanding of image processing concepts
  • Knowledge of 3D matrix structures
  • Experience with image file formats, specifically .jpg and .tiff
NEXT STEPS
  • Learn how to use imread() effectively in MATLAB
  • Research the differences between image formats, particularly .jpg and .tiff
  • Explore MATLAB's imformats function for supported image formats
  • Investigate image compression techniques and their implications in MATLAB
USEFUL FOR

MATLAB users, image processing researchers, and anyone involved in hyperspectral imaging analysis will benefit from this discussion.

Larry Gopnik
Gold Member
Messages
34
Reaction score
19
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:
%-----------------------------%
%----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:
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:
%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:
Physics news on Phys.org
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.
 
  • Like
Likes Larry Gopnik
Image Analyst said:
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.

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
 
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?
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
7K
  • · Replies 7 ·
Replies
7
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 4 ·
Replies
4
Views
15K