http://omploader.org/vNHZuaA is my image. I need to remove the big white part on one side.
I've been googling around and surprisingly this is more difficult to do than I'd have expected. I don't want to use any bash scripts to make this work (although I will if I /have/ to).
Remove an uneven, monochrome border
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Remove an uneven, monochrome border
Why not just trim (-fuzz XX% -trim +repage) the white all around and then pad it back out with white to how ever you want using -border
Re: Remove an uneven, monochrome border
Try it. It does nothing to the image.fmw42 wrote:Why not just trim (-fuzz XX% -trim +repage) the white all around and then pad it back out with white to how ever you want using -border
-
- Posts: 1015
- Joined: 2005-03-21T21:16:57-07:00
Re: Remove an uneven, monochrome border
With ImageMagick, the basic operator to remove the edges is -trim and this would remove the white margins on your image if they were pure white or near-white.
BUT the margins have single black pixels which prevent the -trim operator from working. For example, if you look at your image you will see that there are two black pixels along the top edge at coordinates (865,0) and (866,0) and two black pixels on the bottom edge at (2088,3337) and (2088,3338). Those and other similar spots in the white area can be removed with a median filter although it will also affect the text in the image as well. You'll have to try it and see if it produces an acceptable result.
Pete
BUT the margins have single black pixels which prevent the -trim operator from working. For example, if you look at your image you will see that there are two black pixels along the top edge at coordinates (865,0) and (866,0) and two black pixels on the bottom edge at (2088,3337) and (2088,3338). Those and other similar spots in the white area can be removed with a median filter although it will also affect the text in the image as well. You'll have to try it and see if it produces an acceptable result.
Code: Select all
convert scan-017.pnm -median 0.1 -trim +repage scan-017-trim.png
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
See my message in this topic for a link to a zip of all the files.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Remove an uneven, monochrome border
That is very strange. I have not been able to get it to trim either even with -fuzz 90%.
But I can do this:
convert -size 100x100 xc:black -bordercolor white -border 50 -monochrome temp.pnm
convert temp.pnm -trim +repage temp.png
and it works just fine. Both images are bi-level.
There must be something odd about your image that I don't see (apart from its large size).
But I can do this:
convert -size 100x100 xc:black -bordercolor white -border 50 -monochrome temp.pnm
convert temp.pnm -trim +repage temp.png
and it works just fine. Both images are bi-level.
There must be something odd about your image that I don't see (apart from its large size).
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Remove an uneven, monochrome border
el_supremo has found the issue.
If the odd pixels are near the border, then just crop or shave the border and then trim
So this works:
convert 017.pnm -shave 5x5 -trim +repage -bordercolor white -border 25 017_proc.pnm
and you don't need to worry about the median changing the looks of your text.
If the odd pixels are near the border, then just crop or shave the border and then trim
So this works:
convert 017.pnm -shave 5x5 -trim +repage -bordercolor white -border 25 017_proc.pnm
and you don't need to worry about the median changing the looks of your text.
-
- Posts: 1015
- Joined: 2005-03-21T21:16:57-07:00
Re: Remove an uneven, monochrome border
The shave doesn't really work either because there's a black spot at (171,2565) in the original which prevents the remainder of the white margin being trimmed.
Pete
Pete
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
See my message in this topic for a link to a zip of all the files.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Remove an uneven, monochrome border
el_supremo wrote:The shave doesn't really work either because there's a black spot at (171,2565) in the original which prevents the remainder of the white margin being trimmed.
Pete
Right. Too bad. Then how about:
convert 017.pnm -shave 5x5 -trim -gravity south -chop 0x1 -trim +repage 017_proc.png
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Remove an uneven, monochrome border
The source image is a scan that has been bilevelled to black and white. You might get better results by working from the original scan.
We can make a mask that is entirely white for the almost-white areas of the source and transparent elsewhere, compose that over the source, and trim the result. This single command does two trims, so an optimisation may be possible.
A Windows command, so for Unix etc change "%%" to "%" and "^" to "\":
EDIT: changed the second trim from "+trim" to "-trim".
We can make a mask that is entirely white for the almost-white areas of the source and transparent elsewhere, compose that over the source, and trim the result. This single command does two trims, so an optimisation may be possible.
A Windows command, so for Unix etc change "%%" to "%" and "^" to "\":
Code: Select all
convert ^
scan-017.pnm ^
( ^
+clone ^
-median 0.1 -trim ^
-background rgba(100%%,100%%,100%%,0) -flatten ^
-channel Alpha -negate ^
) ^
-composite ^
-trim +repage ^
sn.png
snibgo's IM pages: im.snibgo.com