Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to convert from YCbCr to RGB?
Forum Updated to NodeBB v4.3 + New Features

How to convert from YCbCr to RGB?

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 1.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ? Offline
    ? Offline
    A Former User
    wrote on 20 Nov 2020, 14:27 last edited by
    #1

    I have an assignment, it is about converting an Rgb Image to YCbCr, modifying the Y Value and then convert it back to Rgb.
    I used the following methods to convert the Image to YCbCr:

    
    void ImageViewer::convert(){
        int height = image->height();
        int width = image->width();
    
    
        QRgb color;
        struct YCBCR yCbCr;
        for (int f1=0; f1<width; f1++) {
            for (int f2=0; f2<height; f2++) {
                 color = image->pixel(f1,f2);
                int red = qRed(color);
                int blue = qBlue(color);
                int green = qGreen(color);
                yCbCr= convertToYCBCR(red,green,blue);
                
    
             image->setPixel(f1, f2, qRgb(yCbCr.Y, yCbCr.CB, yCbCr.CR));
    
            }
      }
    
        updateImageDisplay();
        renewLogging();
    
    }
    
    
    struct YCBCR ImageViewer::convertToYCBCR(int red, int green, int blue) {
        struct YCBCR yCbCr;
    
        yCbCr.Y = (int)(0.229*red + 0.587*green + 0.114*blue);
        yCbCr.CB = (int)(-0.169*red -0.331*green + 0.5*blue )+128;
        yCbCr.CR = (int)(int)(0.5* red - 0.419*green - 0.08*blue) +128;
    
        return yCbCr;
    }
    

    Now i am trying to implement a method to get the Y, CB, and CR values from the converted Image in order to modify the Y and then convert it back to RGB, but i have no Idea how to get the y, CB, CR values from the CONVERTED IMAGE. Is there an algorithm? Any Ideas?

    C 1 Reply Last reply 20 Nov 2020, 14:50
    0
    • ? A Former User
      20 Nov 2020, 14:27

      I have an assignment, it is about converting an Rgb Image to YCbCr, modifying the Y Value and then convert it back to Rgb.
      I used the following methods to convert the Image to YCbCr:

      
      void ImageViewer::convert(){
          int height = image->height();
          int width = image->width();
      
      
          QRgb color;
          struct YCBCR yCbCr;
          for (int f1=0; f1<width; f1++) {
              for (int f2=0; f2<height; f2++) {
                   color = image->pixel(f1,f2);
                  int red = qRed(color);
                  int blue = qBlue(color);
                  int green = qGreen(color);
                  yCbCr= convertToYCBCR(red,green,blue);
                  
      
               image->setPixel(f1, f2, qRgb(yCbCr.Y, yCbCr.CB, yCbCr.CR));
      
              }
        }
      
          updateImageDisplay();
          renewLogging();
      
      }
      
      
      struct YCBCR ImageViewer::convertToYCBCR(int red, int green, int blue) {
          struct YCBCR yCbCr;
      
          yCbCr.Y = (int)(0.229*red + 0.587*green + 0.114*blue);
          yCbCr.CB = (int)(-0.169*red -0.331*green + 0.5*blue )+128;
          yCbCr.CR = (int)(int)(0.5* red - 0.419*green - 0.08*blue) +128;
      
          return yCbCr;
      }
      

      Now i am trying to implement a method to get the Y, CB, and CR values from the converted Image in order to modify the Y and then convert it back to RGB, but i have no Idea how to get the y, CB, CR values from the CONVERTED IMAGE. Is there an algorithm? Any Ideas?

      C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 20 Nov 2020, 14:50 last edited by
      #2

      @Mr-Sin said in How to convert from YCbCr to RGB?:

      but i have no Idea how to get the y, CB, CR values from the CONVERTED IMAGE. Is there an algorithm?

      You can get the rgb pixel from an image with QImage::pixel(). This rgb value can be converted to your YCbCr value and back.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on 20 Nov 2020, 14:55 last edited by
        #3

        Yeah but not after i have converted the image.

        1 Reply Last reply
        0
        • C Offline
          C Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 20 Nov 2020, 17:57 last edited by
          #4

          Why not?

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          0
          • S Offline
            S Offline
            SGaist
            Lifetime Qt Champion
            wrote on 20 Nov 2020, 18:16 last edited by
            #5

            Hi,

            From your code you seem to convert every pixel value, use the reverse formula to change your YCbCr back to RGB. You should have it in the same place as the one for RGB to YCbCr.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            1

            5/5

            20 Nov 2020, 18:16

            • Login

            • Login or register to search.
            5 out of 5
            • First post
              5/5
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved