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

조회 수: 7 (최근 30일)
camilo
camilo 2018년 9월 11일
댓글: Image Analyst 2018년 9월 11일
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