How to save the image obtained from 'imagesc' plot for further processing?

14 views (last 30 days)
Iam using 'dlmread' to read the data and for plotting the data iam using 'imagesc'. first of all is it correct way to save the image in .png or .jpg formats... while Iam saving the image size is changed. (ex: in my data from 2048*130 to 560*420*3). while saving the data xlabel, ylabel and title also visible. actually I want to apply wavelet denoiosing and feature extraction on my data please help me in this regard.
here I have attached my code. I cannot able to attach data files it is not supported.. In this program my bscan image is saved in 'Y_T1', without writing all the code I have copied Y_T1 data in excel sheet and saved in text(Tab delimited), it is saved in notepad file. I recall the file using 'dlmread' and plotted using imagesc... Is it correct way or not?
img=dlmread('Y_T1.txt', '\t', 0, 0);
X_scan=linspace(0,129,44);
df=20e6;
NFFT=2048;
Fs=(NFFT-1)*df;
dt=1/Fs;
T_record=1/df;
T_array=0:dt:T_record;
imagesc(X_scan,T_array,img)
ylim([0 10e-9])

Accepted Answer

Walter Roberson
Walter Roberson on 24 May 2021
Note that image() and imagesc() and imshow() do not accept individual coordinates for each row or column. They ignore everything except the first and last coordinates in a vector of coordinates. So where you imagesc(X_scan,T_array,img) that would be treated like
imagesc([0 129], [0 T_record], img)
You are asking about the size changing when you save the image, but if the size does not change then you need to explain how you want the change in coordinates to be handled. With some file formats it would be possible to set the image resolution headers in the file, so that at some level something knows that your 2048 rows corresponds to 5e-8 units... but that is quite unlikely to be of any practical use.
If you are using a fairly recent version of MATLAB, use
rimg = rescale(img);
and then imwrite() rimg if you really need it saved to a file.
If you are not using quite as modern a version then
rimg = mat2gray(img); %badly named function
You say
I want to apply wavelet denoiosing and feature extraction on my data please help me in this regard.
Doing that does not require writing the data to an image file: you could work directly with the rimg matrix.
  9 Comments
Walter Roberson
Walter Roberson on 28 May 2021
Reminder: when you imwrite() double precision to a png file, the effect is as-if you had first done im2uint8 -- so floor(TheImage * 255) is what gets written to the file. That could lose details. Whereas if you just load the data from the workspace directly, it will not lose the details.
santhosh kumar buddepu
santhosh kumar buddepu on 31 May 2021
No sir, it is not expected to be tall and thin, while plotting using imagesc my image is like as i have uploaded.I have loaded XT2 data directly from workspace still it is like as i uploaded previously.

Sign in to comment.

More Answers (0)

Categories

Find more on Convert Image Type in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!