1

I would like to save in a matrix the plot that imagesc returns. How can I do that? All I know that imagesc returns a handle and I don't know what to do with it.

Kate Gregory
  • 18,808
  • 8
  • 56
  • 85
boshnak
  • 5
  • 3

1 Answers1

0

The data for imagesc is stored in the CData property, so use this to extract it:

X = get(h, 'CData');

assuming h is your handle.

Now X contains your image data, and you can save it to a file, for instance:

save somefile.mat X
Eitan T
  • 32,660
  • 14
  • 72
  • 109
  • for completeness, I'd add this assumes a `h=imagesc(...)` was used, otherwise the `h` doesn't mean a lot. – bla Jan 01 '13 at 19:09
  • @natan it's implied that it's the handle that the OP mentioned in his question, _i. e._ obtained by `imagesc`, but thanks for the clarification. – Eitan T Jan 01 '13 at 19:45
  • First, Thanks. But I already tried that and 'cdata' contains the original image, not what imagesc plots. – boshnak Jan 01 '13 at 20:30
  • @boshnak What's the difference between the original image and the one `imagesc` plots (except the re-scaling)? Can't you extract the original image and scale it "manually"? – Eitan T Jan 02 '13 at 15:31
  • @EitanT I tried to scale it manually but my results weren't so good. I would be happy if you could explain how to do so... – boshnak Jan 03 '13 at 09:15
  • @boshnak `imagesc` scales the data to the range of the current colormap. To scale an image `I` to a range [a, b], do `Iscaled = ((I - min(I)) * (b - a)) / (max(I) - min(I))`. – Eitan T Jan 03 '13 at 09:50