fuzz and trim not working on a png

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
brendan

fuzz and trim not working on a png

Post by brendan »

Hello,
For some reason -fuzz x -trim in not working on a png. The png was converted from a ps image. If I specify a very large fuzz value the image is blank, but keeps the same size.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: fuzz and trim not working on a png

Post by anthony »

A bug fix was added in a later release of image that makes a -trim that completely trims the WHOLE image return a 'one pixel missed image' instead of a blank image.

As for you actual problem can you give a pointer to a small example image, and the exact command you are trying. Also did you use percent with fuzz or not?
Without a percent symbol the -fuzz value is compiletime Q level dependant.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
brendan

Re: fuzz and trim not working on a png

Post by brendan »

The original ps, the first png, and the second png. edit: links to images removed

Commands:

Code: Select all

convert -colorspace RGB -density 288 -trim -filter box -support 1.5 -resize 40% -depth 8 -colors 256 +repage 00Z_EFINE_W3_042H.ps test.png
convert -fuzz 50% -trim -depth 8 -colors 256 test.png test2.png
The initial ps has a thin black border which the first -trim removes. When:

Code: Select all

convert -colorspace RGB -density 288 -trim -filter box -support 1.5 -resize 40% -trim -depth 8 -colors 256 +repage 00Z_EFINE_W3_042H.ps test.png
did not work I thought maybe I have to convert -trim ps to png to remove the black border and and convert-trim again to remove the whitespace. I also added the +repage thinking the postscript pagesize might be part of the issue. Ideally I wanted one command to do all the work so I ended up using -shave, which I did not want to do.
Last edited by brendan on 2007-09-26T05:14:17-07:00, edited 1 time in total.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: fuzz and trim not working on a png

Post by anthony »

Well I am not surprised it did not work.

You are not reading the image in BEFORE operating on it.
IM has a hard time figuring out the exact order of operations when you do that.

Gad... huge images Arrgg, I asked for small images ;-)

First test

Code: Select all

convert -colorspace RGB -density 288 00Z_EFINE_W3_042H.ps -trim +repage -filter box -support 1.5 -resize 40% t.png
No problems. A little fuzzy but that is what you get with a box filter and a larger 'blur support' t.png I generated and your given test.png matched fine.

Ok but trim fails. BUT looking at the trimmed image WITHOUT resizing shows
that there is a VERY thin line surrounding the converted PS image!!!!
You need to do a more complex trim...

test trim (output to display)

Code: Select all

convert -colorspace RGB -density 288 00Z_EFINE_W3_042H.ps -trim -shave 2x2 -trim +repage x:
Now that trims the image, removes the bounding box, then trims again, fully triming down to the image proper.

Final command...

Code: Select all

convert -colorspace RGB -density 288 00Z_EFINE_W3_042H.ps -trim -shave 2x2 -trim +repage -filter box -support 1.5 -resize 40% png8:test.png
The "png8:" taks care of the -depth and -colors requirements as that is the defination for a png8 image (like GIF but using PNG)
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
brendan

Re: fuzz and trim not working on a png

Post by brendan »

Anthony,

Many thanks. I had not used that type of syntax before(obviously). Sorry about the large images, but I am not the person generating the ps images, so I had no way to exactly duplicate the problem. All ps images I ever generate myself(mostly from Matlab) never have this problem. These images are given to me as ps converted from NCAR graphics cgm.

Thanks again.
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: fuzz and trim not working on a png

Post by el_supremo »

Try specifying -bordercolor before -border.

Pete
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: fuzz and trim not working on a png

Post by anthony »

el_supremo wrote:Try specifying -bordercolor before -border.
There was no use of -border in this problem. this was trimming broders, not adding borders.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: fuzz and trim not working on a png

Post by el_supremo »

There was no use of -border in this problem.
There was when I first started typing my reply to the message. When I sent my response, the message I was replying to had disappeared and changed to "Never mind". Curious.

Pete
Post Reply