i need to convert from python to c++

asked 2019-07-04 03:12:28 -0600

Hi everyone, i have done a function in python to convert raw to jpeg with a lookuptable and denoising. The function in python works well but now i need the same function develoiped in c++; The raw is a 16bit 1channel grayscale 1533x1000

                     imageSize = (picture.height, picture.width)
                     if not os.path.exists(picture.output_file_path):
                         npimg = np.fromfile(picture.original_path, dtype=np.uint16)
                         npimg = npimg.reshape(imageSize)
                         npImage = bytescale(npimg)
                         min=np.min(npImage)        # result=144
                         max=np.max(npImage)        # result=216


                        img = LUT[npImage]

                        img2 = img.copy()

in c++

   Mat ycbcrFrame = Mat::zeros(height, width, CV_16UC1);
   Mat ycbcrFrame_final = Mat::zeros(height, width, CV_16U);
   Mat ycbcrFrame_final2 = Mat::zeros(height, width, CV_16U);
   Mat rgbFrame = Mat::zeros(height, width, CV_16UC1);

   Mat lookUpTable(1, 256, CV_16UC1);

   for( int i = 0; i < 256; ++i)
          lookUpTable.at<uchar>(0,i) = uchar(255-i);

    // data.raw is 544 * 288 * 2 = 313344 bytes long
   int rawSize = 2* width * height;

   FILE *file = fopen(rawFileName, "r");
   if (file == NULL)
       cout << "Error opening " << rawFileName << endl;

   fread(ycbcrFrame.data, sizeof(short), rawSize, file);

   //LUT(ycbcrFrame, lookUpTable, rgbFrame);

   ycbcrFrame.convertTo(ycbcrFrame_final, CV_8U,1/256.0);

   imwrite(output_file, ycbcrFrame_final2);

Sorry for the code in c++, is in development. I try to develop a linspace function in c++ but i don't now if is the problem.Now the c++ code works with the LUT call commented and give an image very similar to the python result but much more dark, i need to increase the white part. Someone can help me to create the right lookuptable like in python version?

Thanks Federico

edit retag flag offensive close merge delete


how do you expect an 8bit lookup table to work with 16bit data ?

berak gravatar imageberak ( 2019-07-04 06:24:52 -0600 )edit