How to clean image and get only the signature

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
filipemansano
Posts: 9
Joined: 2017-06-07T12:24:32-07:00
Authentication code: 1151

How to clean image and get only the signature

Post by filipemansano »

Hey!

I trying to remove background and horizontal line in bottom of signature
But the result contains many noises and traces of bottom horizontal line


i'm trying to get only the signature from this image

Original image
http://imgur.com/a/Zyith
(This image is a sample, the script will treat several different images with the same pattern)

Expected Result
http://imgur.com/a/6DSio
(For this result I used Adobe Photoshop)


Result using ImageMagick
http://imgur.com/a/hBPCp

Code used

Code: Select all

C:\imagick\bin\convert.exe ^
  teste.png ^
  -write mpr:ORG ^
  ( +clone ^
    -negate ^
    -morphology Erode rectangle:100x1 ^
    -mask mpr:ORG -morphology Dilate rectangle:100x1 ^
    +mask ^
  )^
  -compose CopyGreen -composite ^
  -normalize ^
  -fuzz 30000 -fill white -opaque "#47FF47" ^
  -fuzz 15000 -fill white -opaque "#FF00FF" ^
  -density 288 -antialias -sharpen 0x3.0 -colorspace GRAY ^
  out.png
  
Version: ImageMagick 6.8.9-1
Last edited by filipemansano on 2017-06-07T13:09:39-07:00, edited 1 time in total.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: How to clean image and get only the signature

Post by Bonzo »

Out of interest why do you want the signature? If it is your signature you have it already from Photoshop.
filipemansano
Posts: 9
Joined: 2017-06-07T12:24:32-07:00
Authentication code: 1151

Re: How to clean image and get only the signature

Post by filipemansano »

Bonzo wrote: 2017-06-07T12:42:20-07:00 Out of interest why do you want the signature? If it is your signature you have it already from Photoshop.
Our clients send the signed contract in our internal system and we want to compare their signature, for that we only need the signature, and extracting the signature with photoshop demands a lot of time and skill of the collaborators
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to clean image and get only the signature

Post by fmw42 »

try

Code: Select all

convert GvCTYAI.png -white-threshold 70% result.png
filipemansano
Posts: 9
Joined: 2017-06-07T12:24:32-07:00
Authentication code: 1151

Re: How to clean image and get only the signature

Post by filipemansano »

fmw42 wrote: 2017-06-07T13:35:02-07:00 try

Code: Select all

convert GvCTYAI.png -white-threshold 70% result.png
Thanks!!
The function worked out, I did not use the value of 70% I used a value number of "10000" and solved

final code

Code: Select all

C:\imagick\bin\convert.exe ^
  teste.png ^
  -write mpr:ORG ^
  ( +clone ^
    -negate ^
    -morphology Erode rectangle:100x1 ^
    -mask mpr:ORG -morphology Dilate rectangle:100x1 ^
    +mask ^
  )^
  -compose CopyGreen -composite ^
  -normalize ^
  -fuzz 30000 -fill white -opaque "#47FF47" ^
  -fuzz 15000 -fill white -opaque "#FF00FF" ^
  -density 288 -antialias -sharpen 0x3.0 -colorspace GRAY ^
  -white-threshold 10000 ^
  out.png
filipemansano
Posts: 9
Joined: 2017-06-07T12:24:32-07:00
Authentication code: 1151

Re: How to clean image and get only the signature

Post by filipemansano »

How to remove content that is circled in red in the image below

http://imgur.com/a/H5H53

In the course of the tests appeared a case where it contains some words next to the signature, tried several ways with the morphoholgy remove, but all messed up the signature, would have a way to remove these letters without affecting the signature design?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to clean image and get only the signature

Post by fmw42 »

Post your image before you add the red. It interferes with a solution and is too hard to remove.

My suggestion is use -connected-componenets to remove small areas (the characters) and leave the one long signature. See http://magick.imagemagick.org/script/co ... onents.php

Code: Select all

convert P6gHiPG.png \
-define connected-components:verbose=true \
-define connected-components:area-threshold=150 \
-define connected-components:mean-color=true \
-connected-components 8 \
P6gHiPG_result.png
Image
filipemansano
Posts: 9
Joined: 2017-06-07T12:24:32-07:00
Authentication code: 1151

Re: How to clean image and get only the signature

Post by filipemansano »

Sorry, this image without red circle

(http://imgur.com/a/A4rgt)

I try to use the connected components option and I get an error
convert.exe: unrecognized option `-connected-components' @ error/convert.c/ConvertImageCommand/1156.

Version: ImageMagick 6.8.9-1 Q16 x64 2014-05-08
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to clean image and get only the signature

Post by fmw42 »

Try my command with this latest image and it should create the same as my result, but without the red on the left edge
filipemansano
Posts: 9
Joined: 2017-06-07T12:24:32-07:00
Authentication code: 1151

Re: How to clean image and get only the signature

Post by filipemansano »

I tried but am getting an IM error alert, which version did you use to perform this command?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to clean image and get only the signature

Post by fmw42 »

IM 6.9.8.10 unix command. if on windows, try

Code: Select all

convert P6gHiPG.png ^
-define connected-components:verbose=true ^
-define connected-components:area-threshold=150 ^
-define connected-components:mean-color=true ^
-connected-components 8 ^
P6gHiPG_result.png
You need a version of ImageMagick that supports connected components. IM 6.8.9.10 or higher. So it looks like your 6.8.9.1 is a few versions too old. Can you upgrade?
filipemansano
Posts: 9
Joined: 2017-06-07T12:24:32-07:00
Authentication code: 1151

Re: How to clean image and get only the signature

Post by filipemansano »

Yes, I upgraded to the latest version
Thank you very much! It worked out
nextbars
Posts: 1
Joined: 2018-07-23T01:48:37-07:00
Authentication code: 1152

Re: How to clean image and get only the signature

Post by nextbars »

Can you guys please help me, im trying to accomplish the same with php imagick library
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to clean image and get only the signature

Post by snibgo »

If this is a serious question, I suggest you consult IMagick documentation.
snibgo's IM pages: im.snibgo.com
Post Reply