CMYK image getting black on applying unsharp mask

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
gegupta
Posts: 30
Joined: 2010-12-03T12:14:09-07:00
Authentication code: 8675308

CMYK image getting black on applying unsharp mask

Post by gegupta »

HI,

IM version: ImageMagick 6.9.6-3 Q16 x86_64 2016-11-09
Webp version: libwebp-0.5.1

I am trying to resize and apply unsharp mask to a CMYK image. If i do this with target format JPG, i see after applying unsharp mask the image blackens. But same is not true if i convert to webp. I wanted to know if there is anything special with this image. Also same is not true for all cmyk images.

CMYK image : https://drive.google.com/open?id=0B_Gde ... VpUMF9VRnM

For JPEG:
Before resize : https://drive.google.com/open?id=0B_Gde ... HdZZFV1bW8
After resize: https://drive.google.com/open?id=0B_Gde ... S0yYjh4LUk
After unsharp mask : https://drive.google.com/open?id=0B_Gde ... 0ZnTHhNblk

For Webp :
Before resize : https://drive.google.com/open?id=0B_Gde ... ndyUzJqbTQ
After resize: https://drive.google.com/open?id=0B_Gde ... WxicUVGUUk
After unsharp mask : https://drive.google.com/open?id=0B_Gde ... lp0dHc1d1k

Steps i am following :

Code: Select all

Image image_;
image_.read(fileName_);
image_.quality(80);
image_.filterType(TriangleFilter);
image_.magick("JPG"/"WEBP");
image_.write("BeforeResize.jpg");
image_.resize( boost::lexical_cast<string>(400+"x"+ 400 + "!");
image_.write("AfterResize.jpg");
image_.unsharpmask(0.8,0.5,1.2,0.05);
image_.write("AfterSHarpen.jpg");
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: CMYK image getting black on applying unsharp mask

Post by fmw42 »

Unsharp probably expects the image to be RGB. I would strongly suggest that you convert to sRGB colorspace (preferably by profiles). Many viewers do not display CMYK properly without a profile. So if you insist on having CMYK output, then convert the input via profile to sRGB, process your image, then convert back to CMYK with a profile.

As a simple test, this seems to work without profiles for me on IM 6.9.6.4 Q16 Mac OSX

Code: Select all

convert cmyk.JPG -colorspace sRGB -resize 400x400! -unsharp 0.8,0.5+1.2+0.05 -colorspace CMYK result.jpg
gegupta
Posts: 30
Joined: 2010-12-03T12:14:09-07:00
Authentication code: 8675308

Re: CMYK image getting black on applying unsharp mask

Post by gegupta »

Is there an API alternate to do it as in in c++?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: CMYK image getting black on applying unsharp mask

Post by fmw42 »

I am sure there is, but I do not use any API, so I cannot help.
Post Reply