Modify

Opened 6 years ago

Closed 5 years ago

#3647 closed Bug (Fixed)

Ghost border artifact with _GDIPlus_ImageResize

Reported by: anonymous Owned by: Jpm
Milestone: 3.3.15.4 Component: Standard UDFs
Version: 3.3.14.0 Severity: None
Keywords: Cc:

Description

The function _GDIPlus_ImageResize creates images that exhibit the "Ghost Border" problem explained here.

It's not all that noticeable unless you're looking for it, however it's significant for my use case. I'm capturing images of text, up-sizing it by 4X with the High Quality Bicubic mode, and then feeding the resulting image into Tesseract OCR. Up-sizing the image drastically improves the OCR, but for some image captures there is not much of a clean border area around the text to begin with, and in those cases the border artifact on the scaled image can sometimes cause incorrect OCR results.

Please consider adding the TileFlipXY option into the resize logic so that the edges of the resized image won't have this artifact. Even aside from my own use case, this is an artifact that somewhat reduces the potential quality of the image.

I'm not sure if TileFlipXY should always be active, or if perhaps it should just be an optional parameter? Best for you to decide I suppose.

Thanks!

Attachments (6)

Test Resize.au3 (5.5 KB) - added by mdepot@… 6 years ago.
Submited code fix for this issue and also ticket #3650
TestImage.png (2.5 KB) - added by anonymous 6 years ago.
TestOldScale.png (53.4 KB) - added by anonymous 6 years ago.
TestOldResize.png (53.4 KB) - added by anonymous 6 years ago.
TestNewScale.png (53.0 KB) - added by anonymous 6 years ago.
TestNewResize.png (53.0 KB) - added by anonymous 6 years ago.

Download all attachments as: .zip

Change History (14)

comment:1 Changed 6 years ago by anonymous

Or to put it another way, in order to prevent the edge from doing interpolation against the default background, provide the DrawImage method with an ImageAttributes instance which has WrapMode set to TileFlipXY.

comment:3 Changed 6 years ago by anonymous

Some obligatory test code:

#include <GDIPlus.au3>
_GDIPlus_Startup()
Local $hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\TestImage.png")
Local $iWidth = _GDIPlus_ImageGetWidth($hImage)
Local $iHeight = _GDIPlus_ImageGetHeight($hImage)
Local $hBitmap = _GDIPlus_ImageResize( _

$hImage, $iWidth * 4, $iHeight * 4, _
$GDIP_INTERPOLATIONMODE_HIGHQUALITYBICUBIC)

_GDIPlus_ImageSaveToFile($hBitmap, @ScriptDir & "\TestResult.png")
Sleep(500)
_GDIPlus_BitmapDispose($hBitmap)
_GDIPlus_ImageDispose($hImage)
_GDIPlus_Shutdown()

comment:4 Changed 6 years ago by anonymous

See also (somewhat) related ticket # 3650

comment:5 Changed 6 years ago by mdepot@…

I created a fix for this issue, as well as the issue in ticket #3650. The fix is within the attached file "Test Resize.au3" It contains replacement functions for _GDIPlus_ImageScale and _GDIPlus_ImageResize, as well as a new function to make a dll call to SetWrapMode on an ImageAttribute. These new functions add an ImageAttribute with WrapMode set to TileFlipXY. Currently it's passing the explicit integer 3 to SetWrapMode, which corresponds to TileFlipXY, but that 3 should be replaced with whatever the proper GDI variable is from the headers. Sorry I didn't have that info handy when I made this. Another improvement that could be made is for _GDIPlus_ImageScale to call _GDIPlus_ImageResize instead of repeating a lot of the same code within. Again, this was just a quick fix though. I'm also attaching some sample images showing old and new results.

Changed 6 years ago by mdepot@…

Submited code fix for this issue and also ticket #3650

Changed 6 years ago by anonymous

Changed 6 years ago by anonymous

Changed 6 years ago by anonymous

Changed 6 years ago by anonymous

Changed 6 years ago by anonymous

comment:7 Changed 5 years ago by Jpm

  • Component changed from AutoIt to Standard UDFs
  • Owner set to Jpm
  • Status changed from new to assigned

comment:8 Changed 5 years ago by Jpm

  • Milestone set to 3.3.15.4
  • Resolution set to Fixed
  • Status changed from assigned to closed

Fixed by revision [12325] in version: 3.3.15.4

Guidelines for posting comments:

  • You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
  • In-depth discussions should take place on the forum.

For more information see the full version of the ticket guidelines here.

Add Comment

Modify Ticket

Action
as closed The owner will remain Jpm.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.