B4J Question [SOLVED] Enlarge image without blurring.

jroriz

Active Member
Licensed User
Longtime User
When I use the canvas to enlarge images, they are blurred. Would it be possible to enlarge the image without blurring?

Original image (attached):
1597271113445.png


Enlarged image which I want (magnifying tool - paint.net image editor)
1597271168965.png


canva drawbitmap result (blurred)
1597271298225.png


code:
B4X:
Sub Button1_Click
    
    Dim can As Canvas, img As Image
    can.Initialize("")
    img.Initialize(File.Dirapp, "original.png")
    
    Dim mag As Int = 20
    
    can.SetSize(img.Width*mag, img.Height*mag)
    
    can.DrawImage(img, 0,0,img.Width*mag, img.Width*mag)
    
    MainForm.RootPane.AddNode(can,200,100,can.Width,can.Height)
    
End Sub
 

Attachments

  • original.png
    original.png
    577 bytes · Views: 175

drgottjr

Expert
Licensed User
Longtime User
you either have to start with a larger image or you have to use a vector image or you have to draw a "6" with a large font. you can't take such a small raster image and enlarge it without losing all sharpness.
 
Upvote 0

xulihang

Active Member
Licensed User
Longtime User
It is not easy to achieve this for bitmap since the data is stored as pixels. There are methods like superpixel: http://waifu2x.udp.jp/ , but not suitable for this situation.
 
Upvote 0

jroriz

Active Member
Licensed User
Longtime User
you either have to start with a larger image or you have to use a vector image or you have to draw a "6" with a large font. you can't take such a small raster image and enlarge it without losing all sharpness.
I'm actually cutting small portions of the screen (playing cards), then using tesseract to decode the corresponding character (A, K, Q, J, 10, 9 ... etc).

I tried with opencv and tensorflow, but it got really complicated.
 
Upvote 0

emexes

Expert
Licensed User
using tesseract to decode the corresponding character (A, K, Q, J, 10, 9 ... etc).
I doubt that magnifying the character bitmaps will help Tesseract or any other OCR.

In fact, if the characters are coming from text rendered to pixels, and not from a scanner or camera, then you probably have advantages such as:

- consistent size
- consistent shape
- perfectly level
- known consistent color
- limited character set
- known position
- known plain background

and you might be better off just whipping up your own brute-force scan-area-using-mask algorithm.

caveat: I'm assuming you're writing to scrape data off your own screen, and we're not trying to do it off of multiple screen sizes, resolutions and color schemes.

I'd be interested to see a few screenshots of what you're trying to capture (I'm assuming online card games, and I happen to be a bit of a gambler myself, so don't be shy ? you're amongst friends here ?).
 
Upvote 0

jroriz

Active Member
Licensed User
Longtime User
I doubt that magnifying the character bitmaps will help Tesseract or any other OCR.

In fact, if the characters are coming from text rendered to pixels, and not from a scanner or camera, then you probably have advantages such as:

- consistent size
- consistent shape
- perfectly level
- known consistent color
- limited character set
- known position
- known plain background

and you might be better off just whipping up your own brute-force scan-area-using-mask algorithm.

caveat: I'm assuming you're writing to scrape data off your own screen, and we're not trying to do it off of multiple screen sizes, resolutions and color schemes.

I'd be interested to see a few screenshots of what you're trying to capture (I'm assuming online card games, and I happen to be a bit of a gambler myself, so don't be shy ? you're amongst friends here ?).
I actually got good results with tesseract, but I had to ENLARGE the size of the images a lot.

There is no problem in showing you an image. The project was to do a real-time probability calculation (which I did!).

See an example below (real size):

1597326252196.png
 
Upvote 0
Top