4 Replies Latest reply on Dec 12, 2011 6:24 PM by Sastradhar

    newbee help for dicom image window center/width manipultation

    Sastradhar Level 1

      We have a flash based dicom viewer and i have the folowing code in action script which i want to replace with pixel bender code. is it possible ?

       

      var img_bmp:BitmapData = new BitmapData(Cols, Rows,false,0);

      for (var y:Number = 0; y <Rows; y++) {

      for (var x:Number = 0; x <Cols; x++) {

      gray =  byteArray.readUnsignedShort()*Slope + Intercept;

      gray = 255 * gray/WindowWidth  -  Min * 255 / WindowWidth;

      gray = uint(gray);

      var r:int = gray;

      var g:int = gray;

      var blue:int = gray;

      var c:uint = (r << 16) | (g << 8) | blue;

          img_bmp.setPixel(x, y, c);

        }

      }

       

      Where byteArray is a unsignedshort  sequnce. Slope, intercept, WindowWidth and Min are constants.

      From the little i understood of the kernel programming the expected input channel cannot be 2 channel or single channel input.

      can any one suggest how i can proceed or give me pointers or for this kind of image manipulation pixel bender is not suitable.

       

      Thanks in advance

      Sastradhar

        • 1. Re: newbee help for dicom image window center/width manipultation
          AIF Bob Level 3

          I am not sure that I entirely understand the filter, but I think a Pixel Bender version of this should be possible. You have a number of constant inputs, one input that moves to a new value each time through (the byte array) and you're setting a single output value for each iteration of the loop. I think the challenges here would be in converting to and from the float format used by Pixel Bender.

           

          The byte array can be structured as an input image and sampled. You might have to pad it to three or four channels, or just encode one and two channel data into three or four channels.

           

          I'd suggest starting with some of the simple Flash / Pixel Bender examples that are around. There are some useful links here:

           

          http://www.adobe.com/devnet/pixelbender.html

           

          particularly Kevin Goldsmith's series that starts with writing filters in the toolkit then moves on to importing them into Flash:

           

          http://www.adobe.com/devnet/pixelbender/articles/creating_effects_pt01.html

          1 person found this helpful
          • 2. Re: newbee help for dicom image window center/width manipultation
            Sastradhar Level 1

            i wrote the below kernel code and compiled using pbutil and it did compile i am having trouble determining the shader width and height.  can some one help me out.

             

            <languageVersion: 1.0;>

             

            kernel pixel

            <   namespace : "TMP";

                 vendor : "TMP";

                 version : 1;

            >

                 {  

                     input image1 src;

                     output pixel3 dst;

                     parameter float Intercept;

                     parameter float Slope;

                     parameter float WindowWidth;

                     parameter float Min;

                      void

                       evaluatePixel()

                     {  

                    float gray = sample(src, outCoord())*Slope + Intercept ;

                          gray =  255.0 * gray/WindowWidth  -  Min * 255.0 / WindowWidth;

                          dst = pixel3(gray,gray,gray);

                    }  

               }

             

             

            can some one tell me how to get the shader width and height so so that pixel bender can only act on 16 bits or did i get the whole thing wrong.

            shader.data.src.input = byteArray;

              shader.data.Slope = Slope;

              shader.data.Intercept = Intercept;

              shader.data.Min = Min;

              shader.data.WindowWidth = WindowWidth;

              shader.data.src.width = Cols >> 1;

              shader.data.src.height = Rows ;

              var myJob:ShaderJob = new ShaderJob(shader, img_bmp,Cols, Rows);

              myJob.addEventListener(ShaderEvent.COMPLETE, pixelComplete);

              myJob.start();

             

            Thanks in advance

            • 3. Re: newbee help for dicom image window center/width manipultation
              AIF Bob Level 3

              I'm not sure what you mean by the shader width and height. If it's the image width and height you need to pass that in as a parameter.

               

              Bob

              • 4. Re: newbee help for dicom image window center/width manipultation
                Sastradhar Level 1

                Thanks  bob i got it finally working the issue was converting the data to float

                <languageVersion: 1.0;>

                 

                kernel pixel

                <   namespace : "dummy";

                     vendor : "dummy";

                     version : 1;

                >

                     {  

                         input image1 src;

                         output pixel3 dst;

                         parameter int WindowWidth;

                         parameter int Min;

                         parameter bool inverted;

                         parameter bool bitalloc;

                          void

                           evaluatePixel()

                         {  

                        float gray;

                              if(bitalloc)

                              gray = float(0xffff)*sample(src, outCoord()) ;

                              else

                              gray = float(0xff)*sample(src, outCoord());

                        int   pi =  (int(255.0*gray) -255*Min)/WindowWidth;

                              gray = float(pi)/float(0xff) ;

                if(inverted) gray = 1.0 - gray;

                              dst = pixel3(gray,gray,gray);

                        }  

                   }