MATLAB Answers

Saving a Matrix as an Image and then extracting same matrix from Image.

1 view (last 30 days)
Fareed Jamali
Fareed Jamali on 30 May 2021
Edited: Fareed Jamali on 30 May 2021
There is a "smag" value that has the type double. I want to save the "smag" matrix in the form of image and send the image to some person. I want the other person to read the image and extract the "smag" value. Now, when I read the image I get a matrix of type uint8. Attaching the smag mat file as a reference.
All I want is to save the smag as a figure and then read the figure to extract the same matrix ("smag") of something similar or near similar.
smag.mat file is attached for the reference. Any help would be appreciated.
clear all
close all
clc
load('smag.mat') %smag is of type double
imwrite(smag,'FigureNew.jpeg');
b=imread('FigureNew.jpeg'); %The b matrix comes out to be of type uint8
%I want to extract the smag value from the matrix b.

Accepted Answer

madhan ravi
madhan ravi on 30 May 2021
SMAG = im2double(b) %
IM2DOUBLE Convert image to double precision. IM2DOUBLE takes an image as input, and returns an image of class double. If the input image is of class double, the output image is identical to it. If the input image is not double, IM2DOUBLE returns the equivalent image of class double, rescaling or offsetting the data as necessary. I2 = IM2DOUBLE(I1) converts the intensity image I1 to double precision, rescaling the data if necessary. RGB2 = IM2DOUBLE(RGB1) converts the truecolor image RGB1 to double precision, rescaling the data if necessary. I = IM2DOUBLE(BW) converts the binary image BW to a double- precision intensity image. X2 = IM2DOUBLE(X1,'indexed') converts the indexed image X1 to double precision, offsetting the data if necessary. Class Support ------------- Intensity and truecolor images can be uint8, uint16, double, logical, single, or int16. Indexed images can be uint8, uint16, double or logical. Binary input images must be logical. The output image is double. Example ------- I1 = reshape(uint8(linspace(1,255,25)),[5 5]) I2 = im2double(I1) See also DOUBLE. Documentation for im2double doc im2double Other functions named im2double codistributed/im2double gpuArray/im2double tall/im2double
  1 Comment
Fareed Jamali
Fareed Jamali on 30 May 2021
Your approach works but the only problem is that there is too much noise as a result. I have attached the smag.mat file in the post. What I am trying to implement is in the link. Thank you for your answer. The part I am coding right now looks like;
clear all
close all
clc
imwrite(smag,'FigureNew.png');
b=imread('FigureNew.png');
smag2=im2double(b);
[x,tx,info] = stftmag2sig(smag2,nfft,Fs,'Window',wind,'OverlapLength',olen); % Works on matlab version R2021a
sound(x,Fs);

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by