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. Hi all ,how to mark a greatest pixel intensity value selected by mouse region
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 2.6k 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.
  • C Offline
    C Offline
    chandrasekhar.embedded
    wrote on last edited by
    #1

    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
    0
    • N Offline
      N Offline
      N.Sumi
      wrote on last edited by N.Sumi
      #2

      @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
      0
      • C Offline
        C Offline
        chandrasekhar.embedded
        wrote on last edited by
        #3

        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).

        kshegunovK 1 Reply Last reply
        0
        • C chandrasekhar.embedded

          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).

          kshegunovK Offline
          kshegunovK Offline
          kshegunov
          Moderators
          wrote on last edited by kshegunov
          #4

          @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
          0
          • C Offline
            C Offline
            chandrasekhar.embedded
            wrote on last edited by
            #5

            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
            0
            • kshegunovK Offline
              kshegunovK Offline
              kshegunov
              Moderators
              wrote on last edited by kshegunov
              #6

              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
              1

              • Login

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