Help: geometric distortion in crop + resize conversion

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
rh744
Posts: 2
Joined: 2016-08-24T23:38:38-07:00
Authentication code: 1151

Help: geometric distortion in crop + resize conversion

Post by rh744 »

Hi all,

Having some issues with the following conversion using ImageMagick-7.0.2-9-portable-Q16-x64 on Windows Server.

Code: Select all

convert 168032_apm_uc.psd -auto-orient -alpha transparent -clip -alpha opaque -trim -density 120 -profile 'C:/icc/sRGB.icc' +profile 'xmp' -resize 1080x1080 168032_apm_uc.psd
The problem is the geometric noise / distortion generated in the output - you can see this in the lighter regions of the below image. Interestingly, we only get this when we use both -clip and -resize in the one command. (If we do one, but not both, we get a normal transformation.) Have already tried applying some different resize filters, but no significant change.

Any tips?

Example Image
(Problem render is on left - normal is on right)

Thanks!
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Help: geometric distortion in crop + resize conversion

Post by snibgo »

There is a kind of interference pattern, perhaps from very high frequency data. You never turn clipping off with "+clip", so trim, profile, resize etc will apply only to the clipped regions.

If that doesn't cure the problem, please provide a link to the image file.
snibgo's IM pages: im.snibgo.com
rh744
Posts: 2
Joined: 2016-08-24T23:38:38-07:00
Authentication code: 1151

Re: Help: geometric distortion in crop + resize conversion

Post by rh744 »

Thanks very much, snibgo.

A modified command of:

Code: Select all

convert 168032_apm_uc.psd -auto-orient -alpha transparent -clip -alpha opaque +clip -trim -density 120 -profile 'C:/icc/sRGB.icc' +profile 'xmp' -resize 800x800 168032_apm_uc.psd
...does indeed remove the interference pattern! However, it also seems to have introduced a loss of sharpness. See example.

I thought it might be excessive jpg compression, so I set it to 92, and also threw in some manual sharpen.

Code: Select all

convert 168032_apm.psd -auto-orient -alpha transparent -clip -alpha opaque +clip -trim -density 1200 -profile 'C:/icc/sRGB.icc' +profile 'xmp' -resize 800x800 -unsharp 0x0.5 -quality 92 168032_SHARP92.jpg
See example.

The result is a little better, but there is still a loss of sharpness when compared to the original. (I want to try and avoid the loss in the first place, rather than adding sharpen later.)

Compare to Control file - desired outcome.

I would upload the source PSD, but it is 1.1Gb...

Any tips appreciated.

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

Re: Help: geometric distortion in crop + resize conversion

Post by fmw42 »

Instead of something like this:

Code: Select all

convert -quiet test.tif -alpha transparent -clip -alpha opaque -strip result.tif

Try something like this (unix syntax):

Code: Select all

identify -quiet -format "%[8BIM:1999,2998:#1]" test.tif  |\
convert -quiet test.tif \( - -negate \) \
-alpha off -compose copy_opacity -composite \
-define tiff:alpha=associated \
result.tif
I have found this to do a better job in terms of antialiasing quality.

Same think should work for PSD, I think.

For conversion to Windows syntax, see http://www.imagemagick.org/Usage/windows/

Remove \ from before ( and from before ) and change end of line \ to ^. I assume Windows allows pipes.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Help: geometric distortion in crop + resize conversion

Post by snibgo »

I couldn't download 1.1 GB!

For sharpness testing, I suggest you don't write to JPEG. It just adds another variable. Save to a lossless format such as PNG.

How did you make the control file? Photoshop is known to add a little sharpening to "pure" resizing.

My favourite method for downsizing while retaining sharpness, without adding ringing or other bad effects, is shown on my page "Resampling with halo minimization": http://im.snibgo.com/resamphm.htm#downshp

It's a bit complex, and slow, and the results are subjective, but I do like them.

You are using Windows, so you could try my script.
snibgo's IM pages: im.snibgo.com
Post Reply