Sarahdata
Sarahdata

Reputation: 339

Reducing image bit depth

I'm working on 800 x 800 pixels images with a bit depth of 24 (PNG format). I assume it means 3 x 8 bits. These images are just black and white (0 or 255). I want to reduce this depth to 8 bit because*, when I process this images in matlab,* I create a 800 x 800 x 3 matrix which has a bigger computational cost than computing 2D matrix.

My idea was to subset the first layer of the matrix in matlab but it seems that I've lost the information because I've nothing left in my matrix.

`Im4=Im4(1:800,1:800);`

Any idea ?

I'm new to image processing and I may not know the basics...

Upvotes: 1

Views: 1701

Answers (2)

andrew
andrew

Reputation: 2469

this is just an alternative (since you are new at matlab image processing its nice to know different methods)

gray_scale = Im4(:,:,1);

This method only works because your image is already grayscale (this likely means red=green=blue). What the code says is from Im4 take all rows and all columns of channel 1 and store it in variable named gray_scale Channel 1 for an RGB image refers to the Red channel.

also the other comments were talking about rgb images or 24bit grayscale. an easy way to check is to take the ORIGINAL image (before processing) and type size(MY_IMAGE_NAME_HERE) this should give you 2 or more numbers.

  1. number of rows
  2. number of columns
  3. if it is there gives the number of channels, color images usually have 3. If there is no 3rd number that means you have a 2d array that is grayscale

Upvotes: 1

Dima
Dima

Reputation: 39419

rgb2gray is probably the safest way to convert an M-by-N-by-3 image into M-by-N.

Upvotes: 1

Related Questions