Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

New to MATLAB?

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

Asked by Naz

Naz (view profile)

on 25 Jun 2012

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.



Naz (view profile)



No products are associated with this question.

1 Answer

Answer by Walter Roberson

Walter Roberson (view profile)

on 25 Jun 2012
Accepted answer

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)

1 Comment


Naz (view profile)

on 25 Jun 2012

Thank's Walter, works well for me.

Walter Roberson

Walter Roberson (view profile)

Contact us