0

I need an image with 8 BPP(Bit per Pixel) to learn image segmentation using tensor flow.

Below is my brief code.

Mat Image;
Image = imread("Input.png",IMREAD_UNCHANGED);

** image synthesis process **

imwrite("C:\\Output.png", Image);

If you're curious about my full source code, you can look at what I asked earlier.

If I check the bpp of the image output in this state, it is 24.

What should I do?

For your information, I've tried making corrections like CV_8UC1, but it doesn't seem to work very well.

SamSic
  • 347
  • 1
  • 4
  • 15
  • If your output image should be in colour and 8-bit, that almost certainly means you want to create an indexed, a.k.a. palette, image. I show how to do that here... https://stackoverflow.com/a/54906864/2836621 – Mark Setchell Feb 28 '19 at 17:19

2 Answers2

3

You're probably reading in a color image, which has three bytes for the red, green and blue color components of each pixel.

If you just need an 8-bit image, you can use a single color component.

If you need to operate on the input image in a sensible way, convert it to grayscale first:

cvtColor(src, bwsrc, cv::COLOR_RGB2GRAY);
rubenvb
  • 74,642
  • 33
  • 187
  • 332
  • Thank you for answer, But I wasn't good at asking questions. I want an rgb image of 8 bits. What do I to put in as a parameter? – SamSic Feb 22 '19 at 09:58
  • 24 bit rgb image -> 8bit rgb image – SamSic Feb 22 '19 at 10:12
  • @HanSeobKim If you want to convert 24 bit RGB image to 8bit RGB image, check this: https://stackoverflow.com/a/7657742/7514664 – Jazz Feb 25 '19 at 10:56
1

Instead of reading image in default format, read image in grayscale format.

Mat Image;
Image = imread("Input.png",IMREAD_GRAYSCALE);

** image synthesis process **

imwrite("C:\\Output.png", Image);

You can check this link for detailed information regarding OpenCV image formats: https://docs.opencv.org/3.0-beta/modules/imgcodecs/doc/reading_and_writing_images.html

Jazz
  • 916
  • 1
  • 8
  • 22