# Revision history [back]

### Working with PGM file. Why my generated PGM file has 3 channels (RGB) ?

I tried to generate PGM file, with this :

ori = imread("images/apple.jpg");
cvtColor(ori, gray, COLOR_BGR2GRAY);

vector<int> params;
params.push_back(IMWRITE_PXM_BINARY);
params.push_back(1);

imwrite("images/apple1.pgm", gray, params);


I could generate PGM file successfully and show it using imshow. However I noticed that my PGM file has 3 channels (RGB), which was unexpected since it's supposed to have just 1 channel per pixel.

I loaded the same file into GIMP and exported it into PGM format. When I tried to show it on OpenCV using imshow as well, it displayed the right channel (1 channel) comparison from GIMP and PGM from my code is below :

Notice at bottom left of each image, number of channel. Any advice which part I'm missing from my PGM conversion ?

### Working with PGM file. Why my generated PGM file has 3 channels (RGB) ?

I tried to generate PGM file, with this :

ori = imread("images/apple.jpg");
cvtColor(ori, gray, COLOR_BGR2GRAY);

vector<int> params;
params.push_back(IMWRITE_PXM_BINARY);
params.push_back(1);

imwrite("images/apple1.pgm", gray, params);

I could generate PGM file successfully and show it using imshow. However I noticed that my PGM file has 3 channels (RGB), which was unexpected since it's supposed to have just 1 channel per pixel.
I loaded the same file into GIMP and exported it into PGM format. When I tried to show it on OpenCV using imshow as well, it displayed the right channel (1 channel) comparison from GIMP and PGM from my code is below :