Crop image based on shape detection ? PAYING $$ IF YOU SOLVE IT!

Do you need consulting from ImageMagick experts and are willing to pay for their expertise? Or are you well versed in ImageMagick and offer paid consulting? If so, post here otherwise post elsewhere for free assistance.
Post Reply
fraizor
Posts: 10
Joined: 2015-06-18T16:33:21-07:00
Authentication code: 6789

Crop image based on shape detection ? PAYING $$ IF YOU SOLVE IT!

Post by fraizor » 2015-06-18T16:36:52-07:00

example 1:
Image

example 2:
Image

example 3:
Image

result of example 1:
Image

is it possible to detect an octagon shape and crop the image on that base ?!!
wha would the best method to isolate that number from the image ?
Last edited by fraizor on 2015-06-18T16:42:06-07:00, edited 1 time in total.

fraizor
Posts: 10
Joined: 2015-06-18T16:33:21-07:00
Authentication code: 6789

Re: Crop image based on shape detection ? PAYING $$ TO ANYONE WHO COULD SOLVE IT!

Post by fraizor » 2015-06-18T16:40:03-07:00

example 1:
Image

example 2:
Image

example 3:
Image

result of example 1:
Image

what would the best method to isolate that number from the image ?

User avatar
fmw42
Posts: 25760
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Crop image based on shape detection ? PAYING $$ IF YOU SOLVE IT!

Post by fmw42 » 2015-06-18T18:24:21-07:00

This works to extract the black letters on the white background. But you have to extract the largest white area count (12119) from the terminal (or write script code to filter the list and get the area count). I can solve that in unix, but do not know windows.

# make the image binary and change the white border to black

Code: Select all

convert 405_B.jpg -threshold 50% -bordercolor white -border 10 -fill black -draw "color 0,0 floodfill" -alpha off -shave 10x10 405_B_floodfill.gif
Image

# get the connected components list of objects -- note the first line is the black backgrouknd and the second line is the largest white region, which is what you want.

Code: Select all

convert 405_B_floodfill.gif -define connected-components:verbose=true -connected-components 4 405_B_objects.png

0: 1272x158+0+0 660.7,78.4 160167 srgb(0,0,0)
39: 179x96+517+23 604.5,70.9 12119 srgb(255,255,255)
102: 154x80+100+42 175.4,83.4 4022 srgb(255,255,255)
126: 132x70+958+52 1026.8,89.1 2660 srgb(255,255,255)
67: 121x78+317+33 362.7,71.1 2133 srgb(255,255,255)
81: 118x77+741+36 785.5,73.5 1972 srgb(255,255,255)
80: 57x67+321+36 347.0,72.5 1942 srgb(0,0,0)
...


# filter the objects so you keep only the black background

Code: Select all

convert 405_B_objects.png -define connected-components:area-threshold=12119 -connected-components 4 -auto-level -morphology erode octagon:1 405_B_objects_ccl.png
Image

# make composite the images to make the background transparent in your original image and then trim and convert the transparent areas to white.

Code: Select all

[code]convert 405_B.jpg 405_B_objects_ccl.png -alpha off -compose copy_opacity -composite -trim +repage -background white -alpha background -alpha off 405_B_result.gif
[/code]

Image

You can now do connected components to extract each black letter in a similar manner. See http://www.imagemagick.org/script/conne ... onents.php

How much are you paying!

fraizor
Posts: 10
Joined: 2015-06-18T16:33:21-07:00
Authentication code: 6789

Re: Crop image based on shape detection ? PAYING $$ IF YOU SOLVE IT!

Post by fraizor » 2015-06-19T04:13:45-07:00

Grate method but the code you provided is working only for 405_B
it is not working for the others .
I'am paying 30$

User avatar
fmw42
Posts: 25760
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Crop image based on shape detection ? PAYING $$ IF YOU SOLVE IT!

Post by fmw42 » 2015-06-19T08:13:56-07:00

You have to change the 12119. It is image dependent as I said above. You have to look at the text listing and find the corresponding value.

For 423_B, this works fine. Notice the new value of 11432. With scripting you can automatically extract the appropriate value as a variable. You did not say what version of IM and what platform you are on. For unix, I can provide that code. But I do not know Windows scripting and syntax for these commands may be slightly different for Windows.

Code: Select all

convert 423_B.jpg -threshold 50% -bordercolor white -border 10 -fill black -draw "color 0,0 floodfill" -alpha off -shave 10x10 423_B_floodfill.gif
convert 423_B_floodfill.gif -define connected-components:verbose=true -connected-components 4 423_B_objects.png

Objects (id: bounding-box centroid area mean-color):
0: 1279x138+0+0 664.6,67.4 138804 srgb(0,0,0)
47: 176x94+561+19 650.1,67.3 11432 srgb(255,255,255)
98: 153x82+148+37 222.7,77.0 4278 srgb(255,255,255)
90: 97x74+421+32 474.0,64.7 2054 srgb(255,255,255)
76: 90x78+363+29 401.0,67.7 1860 srgb(255,255,255)
100: 57x67+367+37 393.2,69.1 1825 srgb(0,0,0)
104: 100x59+789+38 830.8,70.6 1170 srgb(255,255,255)
144: 67x47+859+64 888.4,81.2 977 srgb(255,255,255)

Code: Select all

convert 423_B_objects.png -define connected-components:area-threshold=11432 -connected-components 4 -auto-level -morphology erode octagon:1 423_B_objects_ccl.png
convert 423_B.jpg 423_B_objects_ccl.png -alpha off -compose copy_opacity -composite -trim +repage -background white -alpha background -alpha off 423_B_result.gif
Image

fraizor
Posts: 10
Joined: 2015-06-18T16:33:21-07:00
Authentication code: 6789

Re: Crop image based on shape detection ? PAYING $$ IF YOU SOLVE IT!

Post by fraizor » 2015-06-19T09:31:16-07:00

OK give me a code working for ubuntu and give me PM me your paypal so i could send the money ...
EDIT: i'am using the latest windows version.

on ubuntu is it possible to run a bash script the i could give the image name and output name as a parameter when excuting the script ?
somthing like
bash im.sh input1.jpg output1.jpg

btw: whast is the success rate of extracting the number ?
i dont mind using any version i prefer the version that you have ..

User avatar
fmw42
Posts: 25760
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Crop image based on shape detection ? PAYING $$ IF YOU SOLVE IT!

Post by fmw42 » 2015-06-19T10:21:50-07:00

fraizor wrote:OK give me a code working for ubuntu and give me PM me your paypal so i could send the money ...
EDIT: i'am using the latest windows version.
OK. I will try to get to it later today. Perhaps you can find a Windows expert who can convert it to batch format.
fraizor wrote:on ubuntu is it possible to run a bash script the i could give the image name and output name as a parameter when excuting the script ?
somthing like
bash im.sh input1.jpg output1.jpg
yes. I do that all the time
fraizor wrote:btw: whast is the success rate of extracting the number ?
I have no idea. It depends upon your images. If they are all like the above, then it should be good. But I make no guarantees. So you can experiment with it first before paying. Let me know if it is satisfactory.

fraizor wrote:i dont mind using any version i prefer the version that you have ..
I am using IM 6.9.1.5 Q16 Mac OSX Snow Leopard. If you are not on a current version of IM that includes CCL, then my code will not work.

fraizor
Posts: 10
Joined: 2015-06-18T16:33:21-07:00
Authentication code: 6789

Re: Crop image based on shape detection ? PAYING $$ IF YOU SOLVE IT!

Post by fraizor » 2015-06-19T11:27:20-07:00

Great PM me when you'r done ...

User avatar
fmw42
Posts: 25760
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Crop image based on shape detection ? PAYING $$ IF YOU SOLVE IT!

Post by fmw42 » 2015-06-19T11:52:01-07:00

Here is a unix shell script. You can call it extract.sh or whatever you want. Copy and past it into a text file and be sure to "chmod u+x extract.sh" to make it executable.

Code: Select all

#/bin/bash
infile="$1"
outfile="$2"
inname=`convert "$infile" -format "%t" info:`
list=""
list=`convert "$infile" -threshold 50% -bordercolor white -border 10 \
-fill black -draw "color 0,0 floodfill" -alpha off -shave 10x10 \
-define connected-components:verbose=true -connected-components 4 ${inname}_objects.png`
thresh=`echo "$list" | tail -n +3 | head -n 1 | cut -d\  -f6`
convert "$infile" \
\( ${inname}_objects.png -define connected-components:area-threshold=$thresh -connected-components 4 \
-auto-level -morphology erode octagon:1 \) \
-alpha off -compose copy_opacity -composite \
-trim +repage -background white -alpha background -alpha off "$outfile"
rm -f ${inname}_objects.png
exit 0

Then call it in a terminal window as:

Code: Select all

bash extract.sh 405_B.jpg 405_B_result.png
Change the input and output file names (first is the input and second is the output). You can use file paths if the script and images are not in the same and current directory.

fraizor
Posts: 10
Joined: 2015-06-18T16:33:21-07:00
Authentication code: 6789

Re: Crop image based on shape detection ? PAYING $$ IF YOU SOLVE IT!

Post by fraizor » 2015-06-19T14:05:02-07:00

I'm downloading Ubuntu 15 now.
i just paste the code in a file and name it something .sh then run it right ?

User avatar
fmw42
Posts: 25760
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Crop image based on shape detection ? PAYING $$ IF YOU SOLVE IT!

Post by fmw42 » 2015-06-19T14:44:54-07:00

fraizor wrote:I'm downloading Ubuntu 15 now.
i just paste the code in a file and name it something .sh then run it right ?

You have to make the file executable after you name it. Use

Code: Select all

chmod u+x filename.sh 
Then run it as I mentioned above as

Code: Select all

bash filename.sh input output
You may need to use paths to the input and/or output and possibly the script, if they are not all in the your current directory from which you issue the command.

You need at least IM 6.8.9.10 or higher to run the CCL function.

You can probably get one of the Windows/Unix users who can convert my Unix bash shell script to a Windows .bat file.

fraizor
Posts: 10
Joined: 2015-06-18T16:33:21-07:00
Authentication code: 6789

Re: Crop image based on shape detection ? PAYING $$ IF YOU SOLVE IT!

Post by fraizor » 2015-06-20T05:23:03-07:00

bro i'am getting the number with the symbols when using your script

Image

User avatar
fmw42
Posts: 25760
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Crop image based on shape detection ? PAYING $$ IF YOU SOLVE IT!

Post by fmw42 » 2015-06-20T09:29:28-07:00

You will need to upgrade to IM 6.8.9.10 or higher to run CCL. If you cannot find a binary for ubuntu, then you may have to install from source.

Alternately, post a request here for some Windows user who could convert my script to a Windows .bat file. The code change is just to filter through the text list and extract the area field of the third line (second line of data) from the list and put it into a variable.

fraizor
Posts: 10
Joined: 2015-06-18T16:33:21-07:00
Authentication code: 6789

Re: Crop image based on shape detection ? PAYING $$ IF YOU SOLVE IT!

Post by fraizor » 2015-06-20T15:25:21-07:00

Now every thing is running
Thank you fmw42 you are an awesome member !
the payment will be tomorrow morning

User avatar
fmw42
Posts: 25760
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Crop image based on shape detection ? PAYING $$ IF YOU SOLVE IT!

Post by fmw42 » 2015-06-20T15:55:37-07:00

No rush. Take your time and be sure it works adequately for you.

Post Reply