Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Qt Academy Launch in California!

    Solved Hi all ,how to mark a greatest pixel intensity value selected by mouse region

    General and Desktop
    3
    6
    2218
    Loading More Posts
    • 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.
    • C
      chandrasekhar.embedded last edited by

      am having greatest pixel intensity value ,now i need to mark that perticuler pixel in yellow colour,how can we do suggestions please

      1 Reply Last reply Reply Quote 0
      • N
        N.Sumi last edited by N.Sumi

        @chandrasekhar-embedded

        This more related to Image Processing Question rather than Qt. I am not sure of the solution. But the idea is
        Convert the image in to array. You can use Image threshold operation to find the Highest Pixel value in the 2D Image(U8). Convert all below threshold to 0 and above threshold to 1. Repeat the same process and finally, you will having few pixels which are having highest pixel intensity( these are '1') .Compute the maximum pixel value for each labeled region. Then you can come to know in which label consists the highest pixel intensity. Come out with highest value in the array and change it to new value(Yellow / any). If you are going to use the XY coordinates of the highest pixel for other purpose then it fails.

        I guess, you don't find proper solution here in Qt forum.You can find many on research gate, just do search aircraft detection and marking( approximately the principal is same, you might find solution for marking the brightest part). On Night vision camera's they do similar stuff.

        And even your question is not clear:
        2D/ 3D image? and are you using any other libraries for images? Marking pixel in yellow or yellow mark on the pixel in any particular shape?

        1 Reply Last reply Reply Quote 0
        • C
          chandrasekhar.embedded last edited by

          thanks for the reply, now i find greatest pixel intensity value ,but my doubt is how can we send that greatest pixel value to painter to paint that particular pixel , need to draw as a point on image (2D image).

          kshegunov 1 Reply Last reply Reply Quote 0
          • kshegunov
            kshegunov Moderators @chandrasekhar.embedded last edited by kshegunov

            @chandrasekhar.embedded
            QImage is optimized to use for direct pixel access. Furthermore it's a paint device so you can draw with QPainter onto it.
            http://doc.qt.io/qt-5/qimage.html#details

            Now, depending on your particular needs you may want to load the image in QPixmap or QBitmap and then convert to QImage. Find the pixels you're interested in and draw into another QImage with the same size by means of QPainter. Finally to show on the screen you could convert the QImage back to QPixmap and put it in a QLabel widget or something like this. Certainly more information on what exactly you're trying to achieve would be helpful.

            Kind regards.

            Read and abide by the Qt Code of Conduct

            1 Reply Last reply Reply Quote 0
            • C
              chandrasekhar.embedded last edited by

              thank you followed the same as you suggested once check
              void Dialog::mouseReleaseEvent(QMouseEvent *event)
              {
              emit mousejustpressed(event->pos().x(),event->pos().y());
              QPixmap bw = QPixmap("E:/embedded/crop.png");
              QImage image = bw.toImage();
              ui->dialog_crop->setPixmap(QPixmap::fromImage(image));
              //image = image.convertToFormat(QImage::Format_RGB888);
              image = image.convertToFormat(QImage::Format_RGB888).copy(rubberBand->geometry());

               qDebug() << image.format();
               uchar *bits = image.bits();
               const int imgSize = image.width() * image.height() * 3;
               for (int i = 0; i < imgSize; i++)
               {
                 // qDebug() <<bits[i];
                   if(bits[0]<bits[i])
                   {
                       bits[0]=bits[i];
                   }
               }
                qDebug()<<"maximum intensity pixel="<<bits[0];
                ui->label->setText(QString("max intensity:%1").arg(bits[0]));
                 rubberBand->hide();
              

              }
              void Dialog::paintEvent(QPaintEvent *event)
              {
              QPainter painter(this);
              QPen linepen(Qt::red);
              linepen.setCapStyle(Qt::RoundCap);
              linepen.setWidth(30);
              painter.setRenderHint(QPainter::Antialiasing,true);
              painter.setPen(linepen);
              painter.drawPoint(point);
              }

              1 Reply Last reply Reply Quote 0
              • kshegunov
                kshegunov Moderators last edited by kshegunov

                Consider QPixmap::copy(const QRect &) for retrieving the preview image (instead of converting to QImage and back to QPixmap). Also I'd suggest using the QImage::pixel(const QPoint &) method to work with the pixels instead of iterating through the raw data, for example:

                // Retrieve the maximum lightness component
                qint32 maxLightness = 0;
                for (qint32 x = 0, width = image.width(); x < width; y++)  {
                    for (qint32 y = 0, height = image.height(); y < height; y++)  {
                        // Get the image pixel's lightness
                        qint32 lightness = QColor::fromRgb(image.pixel(x, y)).toHsl().lightness();
                        // Compare with the maximum lightness found so far
                        maxLightness = qMax(maxLightness, lightness);
                    }
                }
                
                // Create the resulting image
                QRgb resultingRgb = QColor::fromHsl(0, 0, maxLightness).toRgb().rgb();  // The RGB used for the maximum lightness pixels
                // Create an image with the same size as the original
                QImage result(image.width(), image.height(), QImage::Format_RGB888);
                // Fill with white color
                result.fill(Qt::white);
                // Iterate through the pixels of the original image
                for (qint32 x = 0, width = image.width(); x < width; y++)  {
                    for (qint32 y = 0, height = image.height(); y < height; y++)  {
                        qint32 lightness = QColor::fromRgb(image.pixel(x, y)).toHsl().lightness();
                        // Check if the pixel's lightness is equal to the maximum lightness
                        if (lightness == maxLightness)
                            result.setPixel(x, y, resultingRgb);  // Set the resulting image's pixel to have the proper gray color
                    }
                }
                // Now result (monochrome QImage) contains the pixels with maximum lightness from the original picture
                

                I hope this helps.
                Kind regards.

                Read and abide by the Qt Code of Conduct

                1 Reply Last reply Reply Quote 1
                • First post
                  Last post