Announcement

Collapse
No announcement yet.

Image Scaling

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Image Scaling

    Hi All,

    I am still doing my image processing work, and have a need to scale images. I did a search and it doesn't seem (to my surprise) that this has been discussed here before. There are many methods for scaling an image such as simple nearest neighbor, then bilinear interpolation and hq2x. These are listed at Wikipedia but there are many more methods.

    I am downsizing an RGB image iteratively (90% of original, 80% of original, etc.) and want to preserve the smoothness of the original as much as possilble, even with slightly less performance. Has anyone done this type of work?

    Best,
    Kevin

  • #2
    Kevin,
    have you tried the built in image scaling. It produces reasonable results for photographic images if the %HALFTONE option is used,

    Paul
    Code:
    'PBCC5.02/PBWin 9.02 program
    #COMPILE EXE
    #DIM ALL
    
    FUNCTION PBMAIN () AS LONG
    LOCAL hWin, hBmp,hFont, nFile, nWidth, nHeight, r AS LONG
    LOCAL MyBitmap AS STRING
                
    MyBitmap = "c:\TestImage.bmp"      'set this to point to your image, must be a bitmap
    'get size of bitmap
    nFile& = FREEFILE
    OPEN MyBitmap FOR BINARY AS nFile
    GET #nFile&, 19, nWidth
    GET #nFile&, 23, nHeight
    CLOSE nFile&
    'load the bitmap
    GRAPHIC BITMAP LOAD MyBitmap,nWidth, nHeight TO hBmp
    
    'create a window to display image
    GRAPHIC WINDOW "Image scaling",10,10,800,600 TO hWin
    GRAPHIC ATTACH hWin,0
    FONT NEW "Courier New",30 TO hFont
    GRAPHIC SET FONT hFont
    
    FOR r = 100 TO 10 STEP -10
        GRAPHIC CLEAR %WHITE
        GRAPHIC STRETCH hBmp, 0, (1,1)-(nWidth,nHeight) TO (1,1)-(nWidth * r / 100, nHeight * r / 100),0,%HALFTONE 
        GRAPHIC PRINT "Scale = ";r/100*100;"%"
        GRAPHIC WAITKEY$
          
    NEXT
    GRAPHIC DETACH
    FONT END hFont
    
    END FUNCTION

    Comment


    • #3
      Scaling

      I ran your code and it looks to do a very good job of scaling while retaining the quality of the image. I guess I need to massage it a bit. I am taking a frame from a video for windows feed which is projected into an array via DIM/AT. I then perform many operations on that array (including rotation and scaling) or on copies of that array (which happen to use your fast array ASM code).

      So I am not working with graphic windows per se. I guess I could project the array onto a window, then stretch and then use get bits to get it back into an array I can work with. The only other issue is that I need to scale as your program does, but need to keep the image centered in the window instead of scaling with the origin in the upper left corner.

      FYI...this whole project is attempting something very difficult. I am trying to accomplish real time object recognition that is invariant to the position of the object. I have some novel ideas in this area and they are working OK, but in order to improve accuracy I need to learn the object at different scales and also with different rotations, which will further enhance the invariant nature of object identification.

      This is a hard problem and I will likely fail as no one in the world has solved it yet. There are good approaches like SIFT and SURF, but they have pitfalls. In any case, I am having fun with it and as I said the results so far are good and probably publishable, but I don't really care about that. I just want to see if I can do a better job than any existing algorithm.

      When you break down this problem and try to solve it you appreciate just how incredible the human brain is and vision in particular.

      Thanks for your code and help...

      Best,
      Kevin

      Comment


      • #4
        Kevin,
        GRAPHIC STRETCH doesn't have to display the result in a window. It can stretch a bitmap in memory into another bitmap in memory. The Source bitmap is set in the GRAPHIC STRETCH statement and the destination is set with the GRAPHIC ATTACH statement.

        You'd probably end up using GRAPHIC SET BITS to write your array to a bitmap, then GRAPHIC STRETCH to scale it then GRAPHIC GET BITS to get the scaled image back into a string where you can access it.


        Good luck with the image recognition, it's not easy!

        Paul.

        Comment


        • #5
          Thanks Paul...

          As far as image recognition, my results have been better than expected. I will be posting a video link soon of this program showing what I have accomplished.

          Comment

          Working...
          X