views:

388

answers:

3

Greetings, I am trying to find an easy way to manipulate an image so that I can decrease the quality of it from 8bit to 3bit.

What would be the easiest way to achieve this? Cheers

+1  A: 

int8 is the smallest integer value in Matlab. You could use only 3 out of 8 bits in int8 by shifting to right any value of any pixel in image.

If you have access to Fixed-Point Toolbox instead, you can use numerictype objects with the simple notation:

T = numerictype(s,w)

Cit. from Matlab's manual:

T = numerictype(s,w) creates a numerictype object with Fixed-point: unspecified scaling, Signed property value s, and word length w.

ZZambia
+4  A: 
Jacob
For a maximum `uint8` value of 255, you would get a rounded-off value of 8, which uses 4 bits. To get a range of 0 to 7, you have to divide by (255/7).
gnovice
Thanks gnovice, corrected and updated the results image.
Jacob
+1  A: 

If you have an image that is stored as a uint8 type in MATLAB, then the pixel values will range from 0 to 255. To limit the values to only 3 bits of precision (thus using only the numbers 0 to 7), you can scale the data as in the following example:

>> data = uint8([0 23 128 200 255]);  % Create some data of type uint8
>> scaledData = data*(7/255)

scaledData =

    0    1    4    5    7

>> class(scaledData)

ans =

uint8

Note that even though the scaled values are limited to the range of 0 to 7, the variable storing them is still a uint8 data type since this is the smallest MATLAB will go. The unused higher bits are simply 0.

Depending on how you output the scaled image data to a file (if you want to do that), you may be able to reduce the precision of the stored values to less than 8 bits (for example, PNG files can store 4-bit types).

gnovice