Page 1 of 1
Remove an uneven, monochrome border
Posted: 2010-07-10T18:16:44-07:00
by kaja
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).
Re: Remove an uneven, monochrome border
Posted: 2010-07-10T18:31:11-07:00
by fmw42
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
Posted: 2010-07-10T18:35:07-07:00
by kaja
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
Try it. It does nothing to the image.
Re: Remove an uneven, monochrome border
Posted: 2010-07-10T18:49:08-07:00
by el_supremo
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.
Code: Select all
convert scan-017.pnm -median 0.1 -trim +repage scan-017-trim.png
Pete
Re: Remove an uneven, monochrome border
Posted: 2010-07-10T18:51:51-07:00
by fmw42
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).
Re: Remove an uneven, monochrome border
Posted: 2010-07-10T18:56:37-07:00
by fmw42
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.
Re: Remove an uneven, monochrome border
Posted: 2010-07-10T20:47:18-07:00
by el_supremo
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
Re: Remove an uneven, monochrome border
Posted: 2010-07-10T23:12:50-07:00
by fmw42
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
Re: Remove an uneven, monochrome border
Posted: 2010-07-11T07:41:08-07:00
by snibgo
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 "\":
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
EDIT: changed the second trim from "+trim" to "-trim".