MATLAB Answers

How to save matrix to workspace instead of plotting using imagesc function

2 views (last 30 days)
Naz
Naz on 25 Jun 2012
Commented: Neda on 28 Sep 2017
I don't understand how imagesc function works (scales), but my images plotted using via that function look better than using imshow. Is there any way to save the scaled image in the workspace instead of displaying it? I tried to debug built-in imagesc.m, but found nothing that scales data. If anyone knows how it's done, please, let me know.

  0 Comments

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 25 Jun 2012
If M is your image, then
minM = min(M(:));
maxM = max(M(:));
scaledM = (M - minM) ./ (maxM - minM);
This will be in the range 0 to 1, so if you want to work with uint8 then uint8(scaledM .* 255)

  8 Comments

Show 5 older comments
Neda
Neda on 27 Sep 2017
Thanks a lot Walter for your reply. Unfortunately, I'm not allow to share the data because of confidentiality. just I can attach the values of info.x and info.y. The size of image with this info.x and info.y turned to 140*180 which I need to save the image with this size. I tried
I = imresize(im_sim,[140 180]);
but as I said I lost information and quality of image changed. In fact this image is my ground truth image, and I need exactly as it is to test my algorithm. I tried
im = imagesc(info.x,info.y,im_sim(:,:,fr)),colormap gray, axis image,
imwrite(im.CData);
G = [im(:).CData];
but again giving the image with 479*616 size. Thank you
Walter Roberson
Walter Roberson on 27 Sep 2017
When you use a vector of xdata or ydata for an image() or imagesc() call, all the entries are ignored except for the first and last entries. So your call is equivalent to
imagesc([0, 180.283902162354], [0, 140.292887029289], im_sim(:,:,fr))
Now, that does not tell it to plot into a 140 x 180 area: it tells it to place the lower left pixel center at data units [0, 0] and the upper right pixel center at data units [180.28, 140.29]. The actual number of pixels used on the screen depends upon the size of the axis. If imresize() is losing too much information for your purposes, then you are almost certainly relying on the fact that the displayed image is displaying more than one pixel per data unit.
You need to decide whether you need the final result to be 140 x 180 or if you need the final result to be some intermediate size between 140 x 180 and 479 x 616. Once you decide on the appropriate output size then you can imresize() to it.

Sign in to comment.

More Answers (0)

Tags