Converting between Classes

Converting images from one class to another is a common operation.
The general syntax for class conversion is

B = class_name(A);

Following are the valid class conversions with their input and output

Name Converts Input to: Valid Input Image Data Classes
im2uintB uintB logical, uintB, uint16, int16, single,and double
im2uint16 uint16 logical, uintB,uint16, int16, single,and double
im2double double logical, uintB, uint16, int16, single,and double
im2single single logical, uintB, uint16, int16, single,and double
mat2gray double in the range [0, 1] logical, uintB, intB, uint16, int16,uint32, int32, single, and double
im2bw logical uintB, uint16,int16, single, and double

Example

>> A = [0.12,0.22,0.32;1.23,1.33,1.43]

A =

    0.1200    0.2200    0.3200
    1.2300    1.3300    1.4300

>> B = im2uint8(A)   % Converts to the following as

B =

   31   56   82
  255  255  255