unperspective : "Number Of Peaks Is Greater Than 4" ?

A plethora of command-line scripts that perform geometric transforms, blurs, sharpens, edging, noise removal, and color manipulations.
Post Reply
larbalette
Posts: 6
Joined: 2016-09-17T13:00:53-07:00
Authentication code: 1151

unperspective : "Number Of Peaks Is Greater Than 4" ?

Post by larbalette » 2016-09-17T13:06:33-07:00

Hello,

I'm trying to run unperspective script that I've just downloaded.
The following arguments are showing a mask that looks good (the perspective of the page I want to process clearly appears white on black with no noise)...

Code: Select all

./unperspective -f 30 -i save IMG_4686.JPG IMG_4686_.JPG
But I have no output...
except this message :

Code: Select all

Number Of Peaks Is Greater Than 4
of, fiddling with -f parameter, sometimes these kind of message (but then the mask is not as good as it was):

Code: Select all

Number Of Peaks = 65 Is Larger Than 40
Am I doing something wrong ?
I running ImageMagick 6.9.4.6

Thanks !

User avatar
fmw42
Posts: 22079
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: unperspective : "Number Of Peaks Is Greater Than 4" ?

Post by fmw42 » 2016-09-17T14:39:59-07:00

No not wrong. It is just that your image border is too rough or the fuzz floodfill "eats" into your image so that it is not a smooth straight edge. The only thing you can do is review the masks and try to find a fuzz value that does not eat into your image data. If you post your image to some place such as dropbox.com and put the link here, I can take a look at it. You can also email me directly with your image to fmw at alink dot net

The algorithm relies upon your being able to do a fuzzy floodfill to separate the background from the foreground image and have clean straight edges. Any textured background will not work. It needs to be a pretty even-colored background outside the main image area.

If you make the -f argument too big, then it will "eat" into the image. If you do not have a uniform background, then if the -f argument is too small, there will be "islands" in the background area that can confuse the script. Some of this latter can be mitigated by the -A argument to remove small areas or areas up to the size specified by -A. The only way I know what is going on with such issues is by looking at the mask. See arguments -i and -k.

larbalette
Posts: 6
Joined: 2016-09-17T13:00:53-07:00
Authentication code: 1151

Re: unperspective : "Number Of Peaks Is Greater Than 4" ?

Post by larbalette » 2016-09-17T23:49:15-07:00

ok, it's probably the reason, then. Before sending you the image, I will try with a uniformed background.
Thanks for your quick reply !

larbalette
Posts: 6
Joined: 2016-09-17T13:00:53-07:00
Authentication code: 1151

Re: unperspective : "Number Of Peaks Is Greater Than 4" ?

Post by larbalette » 2016-09-18T03:34:45-07:00

well, I've tried it with a simple photo, white paper on grey background,
that you can find here
http://arbalette.hopto.org/images/forums/IMG_4764.JPG
tried many -f values with no sucess

Code: Select all

larbalette@larbalette ~/temp/numérisation $ ./unperspective -f 7 -i save IMG_4764.JPG IMG_4764_.JPG 
--- Number Of Peaks = 350 Is Larger Than 40 ---                                                                                                                                    
larbalette@larbalette ~/temp/numérisation $ ./unperspective -f 10 -i save IMG_4764.JPG IMG_4764_.JPG                                                                                 
--- Number Of Peaks = 302 Is Larger Than 40 ---                                                                                                                                    
larbalette@larbalette ~/temp/numérisation $ ./unperspective -f 15 -i save IMG_4764.JPG IMG_4764_.JPG                                                                                 
--- Number Of Peaks = 236 Is Larger Than 40 ---                                                                                                                                    
larbalette@larbalette ~/temp/numérisation $ ./unperspective -f 20 -i save IMG_4764.JPG IMG_4764_.JPG                                                                                
--- Number Of Peaks = 144 Is Larger Than 40 ---                                                                                                                                    
larbalette@larbalette ~/temp/numérisation $ ./unperspective -f 25 -i save IMG_4764.JPG IMG_4764_.JPG                                                                                 
--- Number Of Peaks = 99 Is Larger Than 40 ---                                                                                                                                     
larbalette@larbalette ~/temp/numérisation $ ./unperspective -f 30 -i save IMG_4764.JPG IMG_4764_.JPG                                                                                
--- Number Of Peaks = 87 Is Larger Than 40 ---                                                                                                                                     
larbalette@larbalette ~/temp/numérisation $ ./unperspective -f 40 -i save IMG_4764.JPG IMG_4764_.JPG                                                                                
--- Number Of Peaks = 98 Is Larger Than 40 ---                 

User avatar
fmw42
Posts: 22079
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: unperspective : "Number Of Peaks Is Greater Than 4" ?

Post by fmw42 » 2016-09-18T11:39:41-07:00

Your background is too uneven color/texture. The script cannot cleanly separate the background from the foreground. Even your white is uneven and nearly blends into the background on some parts of it. I will try some things and get back later.

Is this typical of your background? Can you photograph on a more uniform dark colored background?

User avatar
fmw42
Posts: 22079
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: unperspective : "Number Of Peaks Is Greater Than 4" ?

Post by fmw42 » 2016-09-18T13:59:00-07:00

Download my latest version of the script. I made a few minor changes today. Also it seems I forgot to change my examples page for some earlier changes I made. In the following examples I used my autothreshold method rather than fuzz value (-p a), which needs my otsuthresh script.

Your image then works fine with the default values if you scale it down to 25% of the size.

Code: Select all

unperspective -p a -i save -k mask IMG_4764_small.png IMG_4764_small_unp.jpg
But if you leave it at larger sizes, then the boundary gets very rough due to the nature of your background. For best results with your image, you should use the -C channel that best separates the foreground from the background. In this case it seems to be the CMYK black channel.

Code: Select all

unperspective -p a -C black -i save -k mask IMG_4764_small.png MG_4764_small_black_unp.png
If you save the masks using -i and -k arguments, then you will see that at full resolution, you have a very rough boundary, with pits and bumps. These are what are causing the error messages about too many peaks. Also there are some small islands of white outside your image. So you have to add the -A argument to remove the small islands of white. You also have to increase the smoothing using -s 5 and -B 1. And you need to increase the peak detection threshold to -t 8 so that it does not consider these small bump and gaps as peaks. This is really a problem primarily because you have a textured background and very high resolution images.

Code: Select all

unperspective -p a -C black -i save -k mask -A 10 -s 5 -t 8 -B 1 IMG_4764.jpg IMG_4764_unp.jpg

Try these examples. They seem to work for me.

larbalette
Posts: 6
Joined: 2016-09-17T13:00:53-07:00
Authentication code: 1151

Re: unperspective : "Number Of Peaks Is Greater Than 4" ?

Post by larbalette » 2016-09-19T10:50:17-07:00

I must be unlucky...
:(
--- OTSUTHRESH IS NOT AVAILABLE ---
whatever the arguments I'm trying with the "new" script downloaded 5 minutes ago.

User avatar
fmw42
Posts: 22079
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: unperspective : "Number Of Peaks Is Greater Than 4" ?

Post by fmw42 » 2016-09-19T11:19:33-07:00

fmw42 wrote:Download my latest version of the script. I made a few minor changes today. Also it seems I forgot to change my examples page for so earlier changes I made. In the following examples I used my autothreshold method rather than fuzz value (-p a), which needs my otsuthresh script.
You must download and install my script otsuthresh. The documentation for unperspective does say that, though I know the docs are rather long and complicated.

larbalette
Posts: 6
Joined: 2016-09-17T13:00:53-07:00
Authentication code: 1151

Re: unperspective : "Number Of Peaks Is Greater Than 4" ?

Post by larbalette » 2016-09-20T01:54:57-07:00

sorry, I've read it a little bit too quickly !
I kept in mind only the "download the script again" part ! missing the part saying that I need an additionnal script.
I'll try again this evening.
Thanks,

larbalette
Posts: 6
Joined: 2016-09-17T13:00:53-07:00
Authentication code: 1151

Re: unperspective : "Number Of Peaks Is Greater Than 4" ?

Post by larbalette » 2016-09-21T10:59:58-07:00

amazing ! it's working perfectly !
Thanks a lot

Post Reply