Select pixel values from a displayed image
-
wrote on 8 Mar 2016, 07:55 last edited by
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 Championwrote on 8 Mar 2016, 08:58 last edited by mrjj 3 Aug 2016, 09:00
hi
you can access pixels using QImageQRect 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); } }
-
wrote on 8 Mar 2016, 10:30 last edited by
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?
-
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.
2/4