How to read image matrix stored in a structure

I have a letters.mat file which has one variable dataset which is a struct and dataset has 2 more fields as train , test which both are also structures, In train structures 2 fields are images and labels ...images is of 124800*784 unit8 type... I want to read those images and store them in a folder. How can I do that? I used the code load('dataset.mat') train = dataset.train images = train.images; Now when I show the image using imshow() it displays error that Error using imread>parse_inputs (line 450) The file name or URL argument must be a character vector.
Error in imread (line 322) [filename, fmt_s, extraArgs, was_cached_fmt_used] = parse_inputs(cached_fmt, varargin{:});
Error in ex (line 46) imgArray = imread(images)
Can anyone help me with the code? Thanks in advance

12 comentarios

KSSV
KSSV el 12 de Jul. de 2018
imshow is your inbuilt function or you have typed it? What does which imshow give
HJ Akhtar
HJ Akhtar el 12 de Jul. de 2018
It is built in function
HJ Akhtar
HJ Akhtar el 12 de Jul. de 2018
I am sorry... My mistake... this error is shown on the imread() function.. Not on imshow()
HJ Akhtar
HJ Akhtar el 12 de Jul. de 2018
I just want to know how can I read images stored in letters.dataset.train.images 124800*784 uint8 and store them in a folder
Guillaume
Guillaume el 12 de Jul. de 2018
Can you attach your letters.mat.
Can you also show the code you've been using that gives you the error.
The error is very clear, the function expects a character vector (aka a string), you're giving it something else. It doesn't know what to do that.
HJ Akhtar
HJ Akhtar el 12 de Jul. de 2018
I am sorry I cant attach the file it shows error that file exceeds 5MB even after zipping the file... But here is the preview of the file... After executing load('letters.mat') i get dataset 1*1 struct in the workspace...
<<
>>
HJ Akhtar
HJ Akhtar el 12 de Jul. de 2018
And the code I used is load('letters.mat')
images = dataset.train.images;
and i get error on this line
img = imread(images);
KSSV
KSSV el 12 de Jul. de 2018
Are you sure that you are inputting image name in imread?
What is
class(dataset.train.images)
size(dataset.train.images)
HJ Akhtar
HJ Akhtar el 12 de Jul. de 2018
This is shown after running the above code... #Guillaume
KSSV
KSSV el 12 de Jul. de 2018
YOu have the data already in hand...you cannot use imread.
HJ Akhtar
HJ Akhtar el 12 de Jul. de 2018
No, I am not sure... Actually i dont know how to access images from dataset.train.images which is of type uint8 and size 124800*784 #KSSV

Iniciar sesión para comentar.

 Respuesta aceptada

Guillaume
Guillaume el 12 de Jul. de 2018
Editada: Guillaume el 12 de Jul. de 2018
If you want to see the image, it's simply:
imshow(dataset.train.images);
The image is a grayscale image. However, it is puzzling why the field is called images since it contains just one (very big image).
If you want to save the image to disk in its own file:
imwrite(dataset.train.images, 'C:\somewhere\somename.png');
edit: Again, your training dataset contains just one image. However, since it's so big, it's possible that that single image is the result of stitching together several images.

Más respuestas (0)

Categorías

Más información sobre Convert Image Type en Centro de ayuda y File Exchange.

Productos

Versión

R2017b

Etiquetas

Preguntada:

el 12 de Jul. de 2018

Comentada:

el 12 de Jul. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by