3 Replies Latest reply on Feb 22, 2009 9:06 PM by AIF Bob

    change output image size

      Hi guys, is there a way to change the output image size? I can multiply the outCoord() vector with a factor to reduce the apparent output size, but the resolution of the image doesn't change, so there is a transparent area under (and on the right) the new image. Here's my evaluatePixel function with an image of 500x375 that I am trying to reduce by half...

      evaluatePixel()
      {
      float2 sc = outCoord();
      if(sc[0] <= 250.0 && sc[1] <= 187.5)
      outputPixel = sampleLinear(inputImage, float2(sc[0]*2.0, sc[1]*2.0));
      else
      {
      outputPixel = pixel4(0, 0, 0, 0);
      }
      }

      Is there a better way of achieving image resizing? I am using PB 1.1.364221 Build 01.Thanks.
        • 1. Re: change output image size
          AIF Bob Level 3
          quote:

          Originally posted by: mohyneenm
          Hi guys, is there a way to change the output image size?



          The short answer to yur questions is "no", the medium length length answer is "not from within the kernel, but the application can ask for whatever output image size it wants", and the long answer opens up a can of worms.

          A Pixel Bender kernel does not inherently know anything about the size of the images it is processing. Suprisingly enough this is actually a Good Thing - a kernel is all about doing one thing - producing the value of one single pixel in the output. It knows where that pixel is in the output (using outCoord), but it does not know the size of the output image or the size of the input image(s). (It can of course declare parameters and ask whatever application it is being run with to pass in this information but there is no built in way to get any of the size information for inut or output images).

          As an example of why this is a Good Thing, we can split the image up into tiles if we want (perhaps to get more efficient cache use) and get identical results to processing the image all at once.

          There is a fair amount of information in the Pixel Bender documentation related to this question. I'll try and summarize some of it here. All images in Pixel Bender are assumed to be embedded in an infinite plane - for example, you can sample an input image at any coordinates. In the case of images loaded from files (e.g. jpg or png) the images themselves are not infinite so we state that any pixels outside the defined area are transparant black in color. If you sample a pixel off the edge of the defined area you get back (0,0,0,0) (assuming a 4 channel image).

          An application is free to ask the runtime for any size image it wants, and it will get back an image of that size, however if it asks for an enormous image chances are that only part of that image will be defined and the rest of the image will be transparant black.

          The region reasoning functions provide a way for a kernel to tell the runtime how the defined area will change as a result of the kernel being run - take a look at the region reasoning section in the documentation. An application might choose to use this defined region as the area which it will display. Your kernel that multiplies the sampling coordinates by 2 to change the size also requires needed and changed functions to let the runtime system know about the changes in defined area.

          As I said at the start, this is a complex question.
          • 2. Re: change output image size
            Hi Bob, thank you for the elaborate explanation. I am going to access the filter from Flex, so region is not going to be useful for me (as mentioned in the doc, Flash Player doesn't support regions). But since you made it clear that it is not possible from within the kernel, my other option is to do something from the application.

            By application, I am assuming you mean my external Flex application that will use the pbj filter. The reason I need this is because Flex's builtin image resize uses nearest neighbor algorithm which is not good enough for us. When we implemented the bilinear algorithm in flex it was very slow. So, we thought it might be an interesting idea to use Pixel Bender to create a resize filter since PB is super fast and also has a builtin bilinear function.

            Now it seems like if I use this filter, it will do the apparent resize in Flex, but will also leave behind a transparent black region. All I need now is a way to crop that transparent region off my flex app. Am I in the right direction?

            Thanks again for your explanation.
            • 3. Re: change output image size
              AIF Bob Level 3
              quote:


              Hi Bob, thank you for the elaborate explanation.


              I wish the explanation didn't have to be elaborate. This is inherently a complex topic.


              quote:

              By application, I am assuming you mean my external Flex application that will use the pbj filter.


              Yes. Your flex application can call the pixel bender processing with appropriate parameters, and ask for an output image of the appropriate size.

              quote:

              Now it seems like if I use this filter, it will do the apparent resize in Flex, but will also leave behind a transparent black region. All I need now is a way to crop that transparent region off my flex app. Am I in the right direction?


              If I understand you correctly, you have an input image of some given size, and you want to produce an output image of a different size. I assume that your input image size is an integer number of pixels, and that your output image size is also an integer number of pixels (life gets waaay more complicated if you're working at a sub pixel level).

              You need to create an output image buffer of the size you require. When you run your pixel bender filter you need to make sure it is going to fill that buffer - i.e. it will call the evaluatePixel function for every pixel in that output image buffer (unfortunately I am not a flash expert so I'm not certain whether the flash pixel bender processing does this automatically or whether you need to give it the size of the output buffer explicitly - perhaps someone who is a flash expert can chime in here and let us know the details). Assuming you get the size of your output buffer correct there should be no transparent black region to worry about.

              If your pixel bender filter needs to know the final output size it must get that size by using a parameter, and your flash app. will need to pass in the output size.

              I hope this helps.
              1 person found this helpful