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
댓글 수: 0
답변 (1개)
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
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, []);
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!