How to save image file (.png) in a .mat structure?
8 views (last 30 days)
Show older comments
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
0 Comments
Answers (1)
Guillaume
on 11 Sep 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 Comments
Image Analyst
on 11 Sep 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, []);
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!