[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: changing contrast and brightness on the fly



I do something like this in our medical imaging application which also
manipulates MR images retrieved via DICOM and allows the user to
interactively adjust image settings.  However, I included sliders because I
already use the mouse for other things ie. left mouse selects ROI's, middle
mouse zooms in out (click, drag up  ->zoom in, drag down -> zoom out) and
right mouse  moves the image around within the view window. I thought adding
contrast/brightness would make the mouse too busy and you don't see the
values.

Anyways, I implemented it in object graphics.  It really becomes a image
width/level problem rather than brightness/contrast, at least that is what
our Siemens MR console does with the mouse manipulation's you refer to.
This is because the MR data is actually 12 bit ( or 0-4095) and the display
only shows 256 gray levels so you are simply windowing within the 12 bit
scale for the display.

I simply calculate the Image Max and Min values from the Width/Level values
and then use bytscl to create a new image from the original 12 bit data.
The level slider has a range of 0-2047 and the width slider 0-4095.

            ImgMax =  LevVal + WidVal/2
            IF ImgMax GT 4095 THEN ImgMax = 4095

            ImgMin =  LevVal - WidVal/2
            IF ImgMin LT 0 THEN ImgMin = 0

            ; LgImg is the 12 bit original MR data (INTARR(256,256))
            ImgData = BYTSCL( LgImg, MAX= ImgMax, MIN = ImgMin, $
                              TOP= !D.TABLE_SIZE-1 )

            oSliceImg->SetProperty, data= ImgData
            oWindow->Draw, oView

To add mouse interactivity, you add motion and button events to your
WIDGET_DRAW widget and then in your event
handler for your draw widget, you need something like this case statement
note: this is what I do for interactive zooming, you could modify this for
width/level

        'wMainDraw' : BEGIN

          ;Motion Events
            IF (sEvent.type EQ 2) THEN BEGIN
              IF (*pState).btndown EQ 2b THEN BEGIN    ; left mouse 1b,
middle mouse is 2b, right mouse 4b

               ;This is the distance moved since you pressed the middle
mouse and held it during movement
                dataxy =   [sEvent.x - (*pState).ZoomPos[0], $
                            sEvent.y - (*pState).ZoomPos[1] ]

                ; now add your code to adjust window level.width like above
and redraw



                oWindow->Draw, oView

              ENDIF
            ENDIF

             ; Handle other events.
             ;  Button press.
             IF (sEvent.type EQ 0) THEN BEGIN
               IF sEvent.press EQ 2 THEN BEGIN  ;MIDDLE Mouse
                 ;On button press, hold current value of mouse position
                 (*pState).ZoomPos = [sEvent.x,sEvent.y]
                 (*pState).btndown = 2b
                 ; let widget emit motion events while mouse is moving
                 WIDGET_CONTROL, (*pState).wDraw, /DRAW_MOTION
               ENDIF
             ENDIF

             ; Button release.
             IF (sEvent.type EQ 1) THEN BEGIN
               (*pState).btndown = 0b
               WIDGET_CONTROL, (*pState).wDraw, DRAW_MOTION=0
             ENDIF

      END


Email me if you need any more help.

Richard Tyc
Project Engineer
St. Boniface Hospital Research Center
351 Tache Ave
Winnipeg, MB R2H 2A6
Canada

Tel: 204-237-2557
Fax: 204-231-1164
email: richt@sbrc.ca



Ken Mankoff <mankoff@I.HATE.SPAM.cs.colorado.edu> wrote in message
Pine.LNX.4.33.0106152012570.32515-100000@snoe.colorado.edu">news:Pine.LNX.4.33.0106152012570.32515-100000@snoe.colorado.edu...
> >
> > I'm looking for tips on how to implement an image display feature that's
> > bugging me. I'm new to widget programming, trying to get up to speed
> > with David Fanning's book and other helps, but any short-cuts would be
> > appreciated.
> >
> > The job is to display an MRI image and to be able to adjust the image
> > brightness and contrast interactively, without going to any special
> > widgets like sliders. The control I have in mind is to
> > middle-click the image and then have drag right/left control contrast
> > and drag up/down control brightness.
> >
>
> I think brightness adjustment is achieved with alpha channels. May require
> IDL Object Graphics.  There are other ways. Search the groups.google.com
> archive for recent threads on this topic.
>
> IDL> ? cursor ; for your
> IDL> ? !mouse ; second question.
>
> > It sounds easy but I can't find anything similar described on the web
> > etc. to use as a suitable starting point.  Question: is changing the
> > contrast and brightness to be achieved by re-defining the
> > color table and re-scaling the data?
>
> your choice to use data or color scale. use bytscl(), lt & gt to rescale
> the data. Probably easier (for debugging too) to do it on data.
>
> -k.
>
> --
> Ken Mankoff
> LASP://303.492.3264
> http://lasp.colorado.edu/~mankoff/
>
>