Ali
Ali

Reputation: 21

Set the depth of image in Matlab

How can I set the depth of an image to 1 Byte? I import an image with the help of the Matlab Imaging toolbox the following way:

UT = imread('ut.jpg');

Upvotes: 1

Views: 72

Answers (1)

Pablo Jeken Rico
Pablo Jeken Rico

Reputation: 579

Normal RGB images (bitmap, png, etc.) are structured as a matrix with M x N x 3 uint8 entries. Each layer respresents the intensity of one of the main colours (red, blue green). Note, that uint8 has the same meaning as byte. u (unsigned) means it just looks at positive numbers and 8 is the amount of bits that the numbers occupy, which is 0 to 255, 0 being black and 255 white.

In order to convert your image into a single matrix with uint8 (or byte, the same) you have to perform a grey conversion:

UT = imread('ut.jpg');
greyImg = rgb2gray(UT); % conversion to uint8

For more information on how the conversion is calculated and how the weights are distributed between each colour, check out the Matlab documentation.

Upvotes: 1

Related Questions