-Distort on scanned mag. picture and colorspaces

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
markanini
Posts: 14
Joined: 2010-06-15T12:55:03-07:00
Authentication code: 8675308
Location: Malmö, Sweden

-Distort on scanned mag. picture and colorspaces

Post by markanini »

Just doing a tiny rotate operation on a scanned magazine photo, noticed some curious curious things about how input colorspaces interact with the halftone pattern. The basic command is:

Code: Select all

magick imput.jpg -colorspace rgb -filter Quadratic -distort SRT -0.22 -colorspace sRGB output.png
RGB, XYZ, ScRGB, IMS look more or less identical. Closest to the original.
Image

The second group that looks identical is sRGB, LAB, Luv, CIELab, CMYK, CMY, HCL, HCLp, HSB, HSI, HSV, HWB, LCHab, LCHuv, OHTA, Rec601YCbCr, Rec709YCbCr, TRansparent, YCbCr, YDbDr, YIQ, YPbPr and Yuv. Bloctches in the shadows are reduced but introduces blotches in the midtones.
Image

The outliers are RGB Sigmoidal(5.5), Log and HSL:
Image Image Image

After playing around with blending the different ouptuts, in an attempt to cancel out the blotches, I settled on an average of Sigmoidal and Log. Compare to the original on the right.

ImageImage
Last edited by markanini on 2013-08-03T22:32:56-07:00, edited 1 time in total.
User avatar
GreenKoopa
Posts: 457
Joined: 2010-11-04T17:24:08-07:00
Authentication code: 8675308

Re: -Distort on scanned mag. picture and colorspaces

Post by GreenKoopa »

Welcome. magick, does that mean you are using the version 7 alpha? Platform? I have been reading your posts but I honestly have nothing useful to add about filters. I do know a reasonable amount about colorspaces though.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: -Distort on scanned mag. picture and colorspaces

Post by fmw42 »

The use of the "magick" command does imply that he is using IM 7 alpha. For most things in IM 7 you can still use "convert". The magick command will eventually have more features and scriptability.

For IM 7, see
http://www.imagemagick.org/script/porting.php
markanini
Posts: 14
Joined: 2010-06-15T12:55:03-07:00
Authentication code: 8675308
Location: Malmö, Sweden

Re: -Distort on scanned mag. picture and colorspaces

Post by markanini »

GreenKoopa wrote:Welcome. magick, does that mean you are using the version 7 alpha? Platform? I have been reading your posts but I honestly have nothing useful to add about filters. I do know a reasonable amount about colorspaces though.
Thanks! I'm using the IM7 build for Windows since it comes with HDRI, haven't found any broken features yet(except the convert command). I also have IM in Gygwin and I'll be playing with Freds Notch script on images like the one above.

As far as the topic is concerned, until I know any better, I've stumbled upon a curious hack. If you have any idea on how to achieve better results with my method I'm happy to try stuff out.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: -Distort on scanned mag. picture and colorspaces

Post by fmw42 »

Thanks! I'm using the IM7 build for Windows since it comes with HDRI, haven't found any broken features yet(except the convert command).
What seems broken when using "convert" in IM 7? I am sure the developers would like to know so as to fix it.
markanini
Posts: 14
Joined: 2010-06-15T12:55:03-07:00
Authentication code: 8675308
Location: Malmö, Sweden

Re: -Distort on scanned mag. picture and colorspaces

Post by markanini »

fmw42 wrote:
Thanks! I'm using the IM7 build for Windows since it comes with HDRI, haven't found any broken features yet(except the convert command).
What seems broken when using "convert" in IM 7? I am sure the developers would like to know so as to fix it.
"Command can not be found"
User avatar
GreenKoopa
Posts: 457
Joined: 2010-11-04T17:24:08-07:00
Authentication code: 8675308

Re: -Distort on scanned mag. picture and colorspaces

Post by GreenKoopa »

I've been reluctant to try out anything labeled alpha, and I've been unable to find a HDRI build of 6.8.X for Windows. I'm happy to hear that 7 works well! I really should install and learn cygwin, then try building IM myself. Time is against us all.

I don't immediately have any ideas for improvement. I can explain why your colorspace tests fell into the groups they did. I'll find the time if that is of interest or use to you. You obviously know enough to have tried rotating in different colorspaces, so likely you already know. Mostly I saw a new user with two interesting posts receive zero response and I thought I should let you know someone shared an interest in these topics.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: -Distort on scanned mag. picture and colorspaces

Post by fmw42 »

markanini wrote:
fmw42 wrote:
Thanks! I'm using the IM7 build for Windows since it comes with HDRI, haven't found any broken features yet(except the convert command).
What seems broken when using "convert" in IM 7? I am sure the developers would like to know so as to fix it.
"Command can not be found"

That seems very strange. It should be pretty much the same as magick. I have not tested in a while, but convert used to work fine on my Mac.

Perhaps it is just a Windows issue.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: -Distort on scanned mag. picture and colorspaces

Post by fmw42 »

I've been unable to find a HDRI build of 6.8.X for Windows
I do not believe there are any IM 6 builds with HDRI on any platform. You will have to build from source.

It was, I believe, Nicolas Robidoux's request that IM 7 builds have HDRI enabled by default.
markanini
Posts: 14
Joined: 2010-06-15T12:55:03-07:00
Authentication code: 8675308
Location: Malmö, Sweden

Re: -Distort on scanned mag. picture and colorspaces

Post by markanini »

GreenKoopa wrote:I've been reluctant to try out anything labeled alpha, and I've been unable to find a HDRI build of 6.8.X for Windows. I'm happy to hear that 7 works well! I really should install and learn cygwin, then try building IM myself. Time is against us all.

I don't immediately have any ideas for improvement. I can explain why your colorspace tests fell into the groups they did. I'll find the time if that is of interest or use to you. You obviously know enough to have tried rotating in different colorspaces, so likely you already know. Mostly I saw a new user with two interesting posts receive zero response and I thought I should let you know someone shared an interest in these topics.
IM in Cygwin was easy as pie to get running. Just select 'Imagemagick' and 'bc' packages along with the default packages. Move Freds scripts to "C:\cygwin\bin" and you're good to go.

What I'm really wondering from this experiment is whether exploiting '-distort SRT 0' and 'colorspace' operators adds anything useful over other methods for removing halftone patterns like FFT spectrum notching. I have some testing with FFT operations ahead of me but in the mean time I'm not sure what else I can do with the former method, I know IM has some advanced colorspace options (DIY colorspace)that I haven't tried and but I don't understand them well enough.

EDIT: FFT introduces blochy midtones:
Image
Last edited by markanini on 2013-08-10T03:15:57-07:00, edited 1 time in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: -Distort on scanned mag. picture and colorspaces

Post by fmw42 »

markanini wrote:I have some testing with FFT operations ahead
Notch filtering may work if the pattern is regular.

Note after some recent changes to IM at or just before 6.8.6, many of my scripts needed updating. Unfortunately, I have gone through most of my scripts to check and update those that need fixing, but I have not tested any of my FFT or HDRI script, yet. So if you find any problems, let me know and I will see what I can do about it. Please test against one of my examples to be sure the script works before trying you example.

Fred

P.S. What you may be seeing are artifacts from the JPG compression and decompression that are exaggerated by your processing in other colorspace. Does this same thing happen on PNG or TIFF images?

I certainly do not understand why you want to process in most of those color spaces. The most useful are generally either sRGB, linear RGB, XYZ or LAB. Note that IM generally needs an RGB or linear colorspace. It certainly has problems and was not designed to actually do many kinds of processing in CMYK.

You have also picked a rather non-standard filter (quadratic). Was there some reason for using that filter? It does seem to have good (antialiasing) properties for shrinking as per http://www.imagemagick.org/Usage/filter/#summery, but is rather blurry for enlarging.

see also http://www.imagemagick.org/Usage/filter/nicolas/
markanini
Posts: 14
Joined: 2010-06-15T12:55:03-07:00
Authentication code: 8675308
Location: Malmö, Sweden

Re: -Distort on scanned mag. picture and colorspaces

Post by markanini »

Testing a multitude of colorspadces was for the sake of finding a different result. I chose the smooth Quadratic filter to make it easier to focus on the blotches and how they blend with the rest of the image. What do you think about my result vs FFT notch?
ImageImage
My hack, left. FFT, right.
User avatar
GreenKoopa
Posts: 457
Joined: 2010-11-04T17:24:08-07:00
Authentication code: 8675308

Re: -Distort on scanned mag. picture and colorspaces

Post by GreenKoopa »

markanini wrote: What I'm really wondering from this experiment is whether exploiting '-distort SRT 0' and 'colorspace' operators adds anything useful over other methods for removing halftone patterns like FFT spectrum notching.
colorspace is probably useful to think about because it affects most methods, probably including FFT spectrum notching. Are all of your images grayscale? I'm less sure about the tiny rotate. This is just resampling, but in a way that isn't consistent across space. Even changing your center of rotation may change your results. It is best to begin with an aligned scan when possible. If you are working on a general approach and this image is just one example, maybe experiment with other resampling. A half pixel translation up and left? A tiny blur?
fmw42 wrote:I certainly do not understand why you want to process in most of those color spaces.
Agreed that you tried too many. As you showed, they tend to fall into groups anyway. This is especially true for grayscale images. And strictly speaking there are many colorspaces you didn't try. Several of the options can be used in combination.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: -Distort on scanned mag. picture and colorspaces

Post by anthony »

Colorspace essentially distorts the color ordering (and color skew, which is irrelevant for pure grayscale).
The sigmoidal and log methods are basically just providing more control over that handling.

For example sRGB is skewed towards one end of the colorspace (for visual representation), while sigmoidal skews toward midtones to prevent clipping at extremes.

The filter itself is what removes the has pattern. The default filter for distort Robidoux, was selected to try and preserve pixel level patterns, as a no-op distort (like "SRT 0" is a very common practise). It is almost exactly like Mitchell-Netravali in style. In actual fact it is Cubic form of Mathematically determined Sharpened Lanczos filter.

Normal Lanczos filter however has a interesting effect in a 2d (cylindrical or distort) filter handling... Near perfect Hash Pattern Cancelling.

See Distort and Filters in the No-Op case
http://www.imagemagick.org/Usage/filter/#distort_noop

Note this is for a checkerboard 'hash'. Some of the patterns in the image appear to contain different types of ordered dithers.


NOTE: in a no-op case, a distort is actually simply a very very fancy 'convolution' on the image. The filter supplying the cylindrical (radial) function that is used to generate a 'convolution kernel' being applied to the image. Its support window determining the size of the 'kernel', as well as a circular (support) mask. You can use the -define filter:verbose=1 option to get a printout of the details of the filter function.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply