Replacing Color Gdip Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
Archandrion
Posts: 31
Joined: 26 May 2018, 22:23

Replacing Color Gdip

23 Jun 2018, 18:20

I am trying to replace color in an image to prepare it for OCR. I've been able to invert the color with:

Code: [Select all] [Download] GeSHi © Codebox Plus

G2 := Gdip_GraphicsFromImage(pBitmap2), Gdip_SetSmoothingMode(G2, 4), Gdip_SetInterpolationMode(G2, 7)
Gdip_DrawImage(G2, pBitmap, 0, 0, w, h,"","","","", "-1|0|0|0|0|0|-1|0|0|0|0|0|-1|0|0|0|0|0|1|0|1|1|1|0|1")



However I am still having trouble with replacing color. The ImageMagick commands convert.exe File.png -alpha off -fuzz 40% +fill white +opaque "#000000 OutPutFile.png and convert.exe File.png -alpha off -fuzz 30% -fill white -opaque "#C0C0C0" OutPutFile.png seem to do the job but I am trying to achieve the same thing via Gdip. The code below was posted by tic at https://autohotkey.com/board/topic/2944 ... ntry554258 but I can't get it to work. A sample image for testing can be found at https://ibb.co/jV5yZo. Any help is appreciated.

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

User avatar
Xtra
Posts: 1204
Joined: 02 Oct 2015, 12:15

Re: Replacing Color Gdip

23 Jun 2018, 18:46

Change:
Gdip_SaveBitmapToFile(E, "output.png")

To:
Gdip_SaveBitmapToFile(pBitmap, "output.png")

HTH
Archandrion
Posts: 31
Joined: 26 May 2018, 22:23

Re: Replacing Color Gdip

24 Jun 2018, 02:35

Xtra wrote:Change:
Gdip_SaveBitmapToFile(E, "output.png")

To:
Gdip_SaveBitmapToFile(pBitmap, "output.png")

HTH


Even when I change E to pBitmap the output.png does not seem to have any noticeable changes. You can view the images at the links below:
input.png
https://ibb.co/jV5yZo

output.png
https://ibb.co/hwpb4o
Archandrion
Posts: 31
Joined: 26 May 2018, 22:23

Re: Replacing Color Gdip

24 Jun 2018, 06:18

Below is an example of the code that I have gotten working so far for inversion and cropping to match the ImageMagick command convert.exe Input.png -crop 1900x77+7+694 -negate InvertedOutput.png and convert.exe InvertedOutput.png -alpha off -fuzz 30% -fill white -opaque "#C0C0C0" ColorReplaced.png but I'm still trying to find or create a function to do the same for convert.exe InvertedOutput.png -alpha off -fuzz 40% +fill white +opaque "#000000" ColorReplaced.png and convert.exe ColorReplaced.png -alpha off -fuzz 30% -fill white -opaque "#C0C0C0" ColorReplaced2.png using only Gdip as Gdip_FilterColor() does not appear to do anyting even when I change E to pBitmap as shown in the second code block below.


First code block (Working):

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus




Second code block(Not Working):

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

trust_me
Posts: 50
Joined: 29 Jul 2017, 10:46

Re: Replacing Color Gdip

24 Jun 2018, 07:45

Works fine for me ,maybe you could delete the "ColorReplaced2.png" file before running the code again.( in case it cannot overwrite it for some reason )
Archandrion
Posts: 31
Joined: 26 May 2018, 22:23

Re: Replacing Color Gdip

24 Jun 2018, 08:10

trust_me wrote:Works fine for me ,maybe you could delete the "ColorReplaced2.png" file before running the code again.( in case it cannot overwrite it for some reason )


It outputs a file but that file does not have all the light gray silver replaced with white.

Using Gdip_FilterColor()
https://ibb.co/hwpb4o

Using ImageMagick
https://ibb.co/mQk9aT
trust_me
Posts: 50
Joined: 29 Jul 2017, 10:46

Re: Replacing Color Gdip

24 Jun 2018, 09:44

It does....


Image
Archandrion
Posts: 31
Joined: 26 May 2018, 22:23

Re: Replacing Color Gdip

24 Jun 2018, 11:10

trust_me wrote:It does....



Strange I tried it with both AutoHotkey_1.1.29.00 and v2 but the output file did not have the color change. What AutoHotkey.exe version are you using?
trust_me
Posts: 50
Joined: 29 Jul 2017, 10:46

Re: Replacing Color Gdip

24 Jun 2018, 11:22

Image


This is the gdip_all.ahk i am using:
https://www.dropbox.com/s/k9djlvnpmk5o7 ... l.ahk?dl=1
trust_me
Posts: 50
Joined: 29 Jul 2017, 10:46

Re: Replacing Color Gdip  Topic is solved

24 Jun 2018, 11:28

I updated to 1.1.29.01 and it works in replacing the color.But i am using 32bit version of ahk maybe there is a problem if you have 64bit ahk version?
Archandrion
Posts: 31
Joined: 26 May 2018, 22:23

Re: Replacing Color Gdip

24 Jun 2018, 11:36

trust_me wrote:I updated to 1.1.29.01 and it works in replacing the color.But i am using 32bit version of ahk maybe there is a problem if you have 64bit ahk version?


Thanks, yes that was the problem. For some reason Gdip_FilterColor() is not working with the AutohotkeyU64 which is the main version I use.
trust_me
Posts: 50
Joined: 29 Jul 2017, 10:46

Re: Replacing Color Gdip

24 Jun 2018, 11:41

Gdip_FilterColor: the MC code in the function is only compiled for 32bit............
Archandrion
Posts: 31
Joined: 26 May 2018, 22:23

Re: Replacing Color Gdip

24 Jun 2018, 11:52

trust_me wrote:Gdip_FilterColor: the MC code in the function is only compiled for 32bit............


I am unfamiliar with machine code. Could you point me to some reading material or program that might help me to convert it to 64bit. Tried doing a google search but did not find much about using mc code in Autohotkey.
trust_me
Posts: 50
Joined: 29 Jul 2017, 10:46

Re: Replacing Color Gdip

24 Jun 2018, 12:08

https://autohotkey.com/boards/viewtopic.php?t=32

You can ask on the forum there are some members who can do it if you provide the source code.( i am not familiar with it :) )

I guess the source code is here: https://pastebin.com/vFgELSEi

Tic has a gdip "forum" you can also put your request there: https://autohotkey.com/boards/viewtopic.php?t=6517
Archandrion
Posts: 31
Joined: 26 May 2018, 22:23

Re: Replacing Color Gdip

24 Jun 2018, 12:10

trust_me wrote:https://autohotkey.com/boards/viewtopic.php?t=32

You can ask on the forum there are some members who can do it if you provide the source code.( i am not familiar with it :) )

I guess the source code is here: https://pastebin.com/vFgELSEi

Tic has a gdip "forum" you can also put your request there: https://autohotkey.com/boards/viewtopic.php?t=6517



Thanks, actually I was looking up "mc code" but just machine code gave me more results and I'm reading up on it.

Return to “Ask For Help”

Who is online

Users browsing this forum: Exaskryz, jmcall10, newbieforever, S7ewie, truekefir and 20 guests