Implementing a contrast slider with Qslider

  • Hi all. I am working on a project that takes images from a frame grabber and displays them on the screen as a grey map. The values I get range from 0-16k and of course have to be converted to 0-255 to be displayed on the screen. The way this works right now is that the range of values gets split into 256 pieces and displayed as RGB where all 3 values are equal. Now, if my image has pixels mostly around the 5k area, I could say anything below 3k = 0, anything above 5k = 255, and anything in between gets split between 1 and 254 equally.

    To do this, I have two sliders, one for high limit and one for low limit. I have it implemented so that the image gets updated every time the slider is touched. If I go from a max intensity of 16130 to a max intensity of 16120, it works out smoothly. If I try to jump to something like 14000, though, it stalls, presumably because it's trying to display all the intermediate images.

    In the code there is a setting for whether or not to do this, and if it is unchecked, the image updates only when I finally release the slider. However, I would like something in between, that would let me see the image get updated in real-time, but so that it would not try to recalculate every single frame.

    One way I thought about doing it is to make the minimum increment 10 and not 1. Nobody will ever need that kind of precision for what we're doing. Is there anything like this built into QSlider? I can't find anything like that. My quick-solution that I'm having some trouble with at the moment is just reducing the max intensity one tenth of what it should be and then just multiplying by 10 later on. Is there any other solution? In a 3rd party app that I'm basically trying to replace, their contrast sliders work in real-time. I have no idea if that's because they do something to their sliders or if they can just display images faster because they use different methods for it or something. I just use QGraphicsScene and addPixmap for drawing a new image. I hear that can be pretty slow.

    Does anybody have any advice in this matter? How do the pros implement things like this?

  • [quote]Is there anything like this built into QSlider?[/quote]

    [quote]I just use QGraphicsScene and addPixmap for drawing a new image.[/quote]
    Do you remove the old pixmap?

    Arguably, you could create a "graphics object": and modify some properties there based on your sliders. This means you don't create a new object every time, you just modify an existing one. You also don't paint on a pixmap anymore, but on the graphics view.

  • I clear the QGraphicsScene by calling myscene.clear();

    When I didn't do this, the program would balloon in memory and quickly crash. I'll try what you suggested. Thanks.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.