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

7 次查看(过去 30 天)
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

回答(1 个)

Guillaume
Guillaume 2018-9-11
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 个评论
camilo
camilo 2018-9-11
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 2018-9-11
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, []);

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Images 的更多信息

产品


版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by