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

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

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

Thank you sir for your reply,
but my problem is I need to create some database for feature extraction and after classification. while saving the image from imagesc plot, it is giving labels and tiltles also.
for example I want to use wavelet analyzer tool box (wavelet 2D)foe denoising, there I need to give image, it is not accepting my Y_T1.txt file, but my image is having labels and title also, it is not correct way to procees avgremoval_img.jpg.
so, how to create my own database with different target images
As I said,
"and then imwrite() rimg if you really need it saved to a file."
When you imwrite() an array, titles and ticks are not saved in the image.
Besides: when you use waveletAnalyzer the File menu has Import from Workspace, which permits you to load arrays from the workspace, so you do not need to save to an image file for this purpose.
sir,
I have imported workspace in wavelet analyzer but I got output like as I uploaded the figure.
and I have used imwrite imwrite (rescale(Hy_r'), 'NEW IMAGE.png'); but my image is saved like as i uploaded. What should I do sir now.
and Iam adding one more figure with image I have saved after imagesc plot in jpg format it consists of labels and title, it is processing with all those stuff
Then perhaps you should not be using print() or saveas() or getframe() on the imagesc() plot. Perhaps you should instead follow my suggestion from earlier to use rescale() or mat2gray() to create a matrix that has had the scaling done to it the same as if you had used imagesc(), after which you would either use the resulting matrix or imwrite() the scaled matrix to a file.
I did the same thing..
imwrite (rescale(Hy_r'), 'NEW IMAGE.png');
[XT2,map] = imread ('NEW IMAGE.png');
figure,imagesc(X,z_depth,XT2)
again I have taken XT2 from workspace in wavelet analyzer but it is taking like this as I have uploaded
I do not see any problem with that last one you show. Your image is 1300 x 32 so it is to be expected that it is tall and thin.
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.
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 Images 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!