Cropping picture and rejoining them
-
- Posts: 7
- Joined: 2015-11-24T06:24:11-07:00
- Authentication code: 1151
Cropping picture and rejoining them
Hi guys,
i need your help.
I've a picture with size 324x324
and i wanna cut out all 16 numbers with specific Geometry Specifications and set it back together.
The goal is to do this as quick as possible because after that comes OCR.
Right now i crop every single number individually, so 16 times convert -crop (convert 1.png -crop 46x46+0+18 1%d.png) and once (montage -geometry 324x324) So that takes quiet a long time.
Every single number is 46x46
X = 0,88,172,258
Y = 18,105,192,278
I tried with a bit cutting in lines and rows or Tile Cropping.
I think Tile Cropping would be a good solution but i've no idea how.
Best solution would be a two liner.
Can anyone help?
i need your help.
I've a picture with size 324x324
and i wanna cut out all 16 numbers with specific Geometry Specifications and set it back together.
The goal is to do this as quick as possible because after that comes OCR.
Right now i crop every single number individually, so 16 times convert -crop (convert 1.png -crop 46x46+0+18 1%d.png) and once (montage -geometry 324x324) So that takes quiet a long time.
Every single number is 46x46
X = 0,88,172,258
Y = 18,105,192,278
I tried with a bit cutting in lines and rows or Tile Cropping.
I think Tile Cropping would be a good solution but i've no idea how.
Best solution would be a two liner.
Can anyone help?
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Cropping picture and rejoining them
What is your IM version and platform? I am not sure I understand fully. Can you explain and show one of the cropped sections.
Are you cropping at the grid lines or the light blue squares? If you can crop to the bounds of all the tiles you want and if they are equally spaced, then you can crop them all in one command. See http://www.imagemagick.org/Usage/crop/#crop_equal and the @ key.
Are you cropping at the grid lines or the light blue squares? If you can crop to the bounds of all the tiles you want and if they are equally spaced, then you can crop them all in one command. See http://www.imagemagick.org/Usage/crop/#crop_equal and the @ key.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Cropping picture and rejoining them
P.S. Are the grid lines in your image real or there to show how you want to crop? Are you not missing one line at the bottom of the row of
1 1 -1 1.
1 1 -1 1.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Cropping picture and rejoining them
Perhaps you can provide the exact commands you use for the above example and post your final output as well.
-
- Posts: 7
- Joined: 2015-11-24T06:24:11-07:00
- Authentication code: 1151
Re: Cropping picture and rejoining them
True, i missed one. But i added them via Photoshop. Just to get easier x and y.
And yes, i thoight of equal one too. But there are not equal. So i need extra code to determine where to cut exactly
Thats one example
And thats my code
And yes, i thoight of equal one too. But there are not equal. So i need extra code to determine where to cut exactly
Thats one example
And thats my code
Code: Select all
os.system("screencapture -x -t png -R 795,270,324,324 %s" % (filename))
os.system("convert %d.png -crop 46x46+0+18 %s" %(i,filename1))
os.system("convert %d.png -crop 46x46+88+18 %s" %(i,filename2))
os.system("convert %d.png -crop 46x46+172+18 %s" %(i,filename3))
os.system("convert %d.png -crop 46x46+258+18 %s" %(i,filename4))
os.system("convert %d.png -crop 46x46+0+105 %s" %(i,filename5))
os.system("convert %d.png -crop 46x46+88+105 %s" %(i,filename6))
os.system("convert %d.png -crop 46x46+172+105 %s" %(i,filename7))
os.system("convert %d.png -crop 46x46+258+105 %s" %(i,filename8))
os.system("convert %d.png -crop 46x46+0+192 %s" %(i,filename9))
os.system("convert %d.png -crop 46x46+88+192 %s" %(i,filename10))
os.system("convert %d.png -crop 46x46+172+192 %s" %(i,filename11))
os.system("convert %d.png -crop 46x46+258+192 %s" %(i,filename12))
os.system("convert %d.png -crop 46x46+0+278 %s" %(i,filename13))
os.system("convert %d.png -crop 46x46+88+278 %s" %(i,filename14))
os.system("convert %d.png -crop 46x46+172+278 %s" %(i,filename15))
os.system("convert %d.png -crop 46x46+258+278 %s" %(i,filename16))
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Cropping picture and rejoining them
Can you post your input image (%d.png)? Why not just crop each character's bounding blue box first, then shave off the tops?
-
- Posts: 7
- Joined: 2015-11-24T06:24:11-07:00
- Authentication code: 1151
Re: Cropping picture and rejoining them
My input image is that first picture i posted, just not that original.
Here is one http://i.imgur.com/5hQb0To.png
What do you mean with crop each caracter?
Would not that mean i would have 16 individual commands?
Here is one http://i.imgur.com/5hQb0To.png
What do you mean with crop each caracter?
Would not that mean i would have 16 individual commands?
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Cropping picture and rejoining them
try these two cropping commands (unix syntax)
Input:
On Unix, you can also pipe them to montage. For example
Input:
Code: Select all
convert 5hQb0To.png -trim +repage -crop 4x4@ +repage \
-fuzz 30% -trim +repage tmp1_%d.png
Code: Select all
convert 5hQb0To.png -trim +repage -crop 4x4@ +repage \
-fuzz 5% -trim +repage -gravity north -chop 0x15 tmp2_%d.png
Code: Select all
convert 5hQb0To.png -trim +repage -crop 4x4@ +repage \
-fuzz 30% -trim +repage miff:- |\
montage - -tile 4x4 -geometry +5+5 -background "#00809F" result1.png
Code: Select all
convert 5hQb0To.png -trim +repage -crop 4x4@ +repage \
-fuzz 5% -trim +repage -gravity north -chop 0x15 miff:- |\
montage - -tile 4x4 -geometry +0+0 -background "#00809F" result2.png
Code: Select all
convert 5hQb0To.png -trim +repage -crop 4x4@ +repage \
-fuzz 30% -trim +repage -background "#00809F" -gravity center -extent 46x46 miff:- |\
montage - -tile 4x4 -geometry +0+0 result3.png
Code: Select all
convert 5hQb0To.png -trim +repage -crop 4x4@ +repage \
-fuzz 30% -trim +repage \
-fuzz 40% -fill white -opaque "#B1EEFC" -fill black +opaque white \
-background black -gravity center -extent 46x46 miff:- |\
montage - -tile 4x4 -geometry +0+0 result4.png
-
- Posts: 7
- Joined: 2015-11-24T06:24:11-07:00
- Authentication code: 1151
Re: Cropping picture and rejoining them
Wow! Nice Work! Thank you so much!
That's actually the solution. It speeds up my total execution time.
If you wanna have a challenge.
Another problem is with screenshots like that
http://imgur.com/QB6IUau
http://imgur.com/r2G05kj
And your commands will execute like these
http://imgur.com/4UMXeZC
http://imgur.com/93K66Bg
So if i run OCR over i, it results in
an more weird symbols.
I've written an Algorithm that removes them, but it slows it down.
So, if you find a solution for that with ImageMagick you're genius.
Thanks again for that solution above!
That's actually the solution. It speeds up my total execution time.
If you wanna have a challenge.
Another problem is with screenshots like that
http://imgur.com/QB6IUau
http://imgur.com/r2G05kj
And your commands will execute like these
http://imgur.com/4UMXeZC
http://imgur.com/93K66Bg
So if i run OCR over i, it results in
Code: Select all
6 -2 4 3
1 5- -2 4
8 2 9 6
-2 3 9 4
I've written an Algorithm that removes them, but it slows it down.
So, if you find a solution for that with ImageMagick you're genius.
Thanks again for that solution above!
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Cropping picture and rejoining them
try this:
Input:
Input:
Code: Select all
convert r2G05kj.png -trim +repage \
-fuzz 40% -fill white -opaque "#B1EEFC" -fill black +opaque white \
-crop 4x4@ +repage \
-trim +repage \
-background black -gravity center -extent 46x46 miff:- |\
montage - -tile 4x4 -geometry +0+0 result5.png
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Cropping picture and rejoining them
I am not sure why you have to crop them? You can do just the following:
Code: Select all
convert r2G05kj.png -trim +repage \
-fuzz 35% -fill white -opaque "#B1EEFC" -fill black +opaque white \
result6.png
-
- Posts: 7
- Joined: 2015-11-24T06:24:11-07:00
- Authentication code: 1151
Re: Cropping picture and rejoining them
You're right. Didn't know you could do that so easily.
Actually i was able to cut down CPU Time from 10 to und 1 deciseconds.
Problem is still, there's room for error.
Like on these picture's:
OCR will produce something like this:
http://imgur.com/71ycHJM
http://imgur.com/8TXrHLl
Any ideas?
Actually i was able to cut down CPU Time from 10 to und 1 deciseconds.
Problem is still, there's room for error.
Like on these picture's:
OCR will produce something like this:
http://imgur.com/71ycHJM
http://imgur.com/8TXrHLl
That's why i wanted to crop it. To eliminate those errors.2 9 1 7
-1 2 5 7
0
1 7 2 9
7 -3 3 -2
Any ideas?
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Cropping picture and rejoining them
try using a smaller fuzz value and optionally dilating the characters using -morphology
Input:
Input:
Code: Select all
convert 71ycHJM.png -trim +repage \
-fuzz 20% -fill white -opaque "#B1EEFC" -fill black +opaque white \
result7.png
Code: Select all
convert 71ycHJM.png -trim +repage \
-fuzz 20% -fill white -opaque "#B1EEFC" -fill black +opaque white \
-morphology dilate diamond:1 \
result8.png
-
- Posts: 7
- Joined: 2015-11-24T06:24:11-07:00
- Authentication code: 1151
Re: Cropping picture and rejoining them
Good idea!
I see what you doing there, but i've a problem when the colors are changing like
http://imgur.com/a/tzCPb
so i end up having a picture like this
That example was made with 20% fuzz and following command:
I know i can get the color of a single pixel in a picture.
Would that help me to change this light blue color to a light pink color?
I could increase 'fuzz', but then the chance the disturbing elements would appear again.
EDIT:
so i figuerd follow fuzz values to the according colors coming up
purple, turquoise, light and dark blue 20% to 25%
orange 40%
red,pink 35%
green, i think 30% something
I see what you doing there, but i've a problem when the colors are changing like
http://imgur.com/a/tzCPb
so i end up having a picture like this
That example was made with 20% fuzz and following command:
Code: Select all
convert 50png -trim +repage -fuzz 20% -fill white -opaque '#B1EEFC' -fill black +opaque white -morphology dilate diamond:1 -quiet 50out.png
Would that help me to change this light blue color to a light pink color?
I could increase 'fuzz', but then the chance the disturbing elements would appear again.
EDIT:
so i figuerd follow fuzz values to the according colors coming up
purple, turquoise, light and dark blue 20% to 25%
orange 40%
red,pink 35%
green, i think 30% something
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Cropping picture and rejoining them
You need to change the -opaque '#B1EEFC' to the color of a pixel in the numbers. You can change the fuzz value to suit.