Important: Please read the Qt Code of Conduct -

Select pixel values from a displayed image

  • Is there a way after displaying an image to select the wanted pixel values from the image? For example, I display a grayscale image and want to select some pixel values - location of it and the value and save it in some data structure in my app to further do some stuff with it.

  • Lifetime Qt Champion

    you can access pixels using QImage

    QRect area(0, 0, 100, 100); // set to some area
    //grab area from pixmap
    QImage image = pixmap()->toImage().convertToFormat(QImage::Format_RGB888).copy(area);
    double row = image.width();
    double col = image.height();
    for(int i = 0; i < row; i++) {
      for(int j = 0; j < col; j++) {
        double intensity = image.pixel(i, j);

  • Thank you for your reply. Maybe I formulated my question not very precisely but after displaying an image I want to select the particular pixels with my mouse, say 10 pixels, which are located at different positions and save those locations (maybe including values) to some data structure in my app.

    Even better, it would be perfect to be able to draw an arbitrary shape of the contour in the image with the mouse and extract those pixels which lie on this contour. Is it possible to do with Qt or do I need additional libraries?

  • Lifetime Qt Champion

    well using
    MouseMoveEvent you can see
    where mouse is all the time and you can then use
    Image.pixel(x,y) to read pixel values.

    So yes its possible.