How to save image file (.png) in a .mat structure?

7 visualizaciones (últimos 30 días)
camilo
camilo el 11 de Sept. de 2018
Comentada: Image Analyst el 11 de Sept. de 2018
Hello everybody, i'm having several troubles saving images in a database. The database is a .mat file with many fields who have alphanumeric values (no problem until here). Some of these fields need to be .png images. Something is not working properly because when i save the .mat file and then i open it again, it apear an error when calling the field with images:
for i = 1:n
Estacion(i).Nombre = ['ASD'];
Estacion(i).Estado = ['test01'];
Estacion(i).Localidad.Lat = [1];
Estacion(i).Localidad.Lon = [2];
Estacion(i).Localidad.MSNM = [3];
Estacion(i).Referencia = ['asd'];
Estacion(i).Graficas.Vs = image(imread('img1.png')); % HERE'S THE PROBLEM!
Estacion(i).Graficas.HVSR = image(imread('img2.png'));
end
save('Estacion.mat','Estacion')
Then, when i call the fields with images, for example the j-th field:
Estacion(j).Graficas.Vs
ans =
handle to deleted Image
when i want matlab show me the image i previously saved in that field. I know that i'm doing something wrong but i can not be able to fix it yet. I read something about the image handle but i dont understand well how to solve this issue.
Hope you can help me. Thank you very much

Respuestas (1)

Guillaume
Guillaume el 11 de Sept. de 2018
I'm not sure what you think image does. It's a function to display a matrix as an image. For an image, you'd be better off using imshow. Anyway, as said, it's for displaying. To store the image, you'd just keep the image returned by imread, so:
Estacion(i).Graficas.Vs = imread('img1.png');
Estacion(i).Graficas.HVSR = imread('img2.png');
  3 comentarios
camilo
camilo el 11 de Sept. de 2018
But when i call back the image with
Estacion(j).Graficas.Vs
It shows the matrix with numbers instead of an image (MxNx3 uint8 variable). How can i show the image directly instead the matrix with numbers?
Image Analyst
Image Analyst el 11 de Sept. de 2018
If you just put a variable on the command line without a semicolon, it will spew the value(s) out to the command window. If you want to display the variable as an image use imshow():
imshow(Estacion(j).Graficas.Vs, []);

Iniciar sesión para comentar.

Categorías

Más información sobre Images en Help Center y File Exchange.

Productos


Versión

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by