Incorrect Color conversion with SIPS

Hi,

I need to convert CMYK with embedded profiles (example Uncoated Forgra 29) to “web” sRGB.

using sips and -M with perceptual “should” bypass the BCP (Black Point Compensation) problem. Sips don’t have BCP like Photoshop.

If I do In Photoshop using convert to profile, Apple CMM, Perceptual and no Black Point Compensation, the RGB conversion is OK.

Same approach with sips washed out the image.

Seems that rendering intent is sips is bugged.

Anyone as a workaround for this?

Maybe ASOC to read the images and with Cocoa command convert the to sRGB with profile conversion?

Ame

Maybe it can be done with Image Magick?
It’s commandline tools for image manipulation that can be downloaded from Macports.org.

By the way, there is no need for X11 to use Gimp anymore.

Using ImageMagick works with some tricks that are in contrast to what they say in the manual.
But you have, before, to extract the icc profile from image.
And -profile command need to be used two time CMYK->CMYK>RGB vene if the documentation say to don’t do this.

I posted the question here:

http://www.imagemagick.org/discourse-server/viewtopic.php?f=1&t=22665

Ame

Does this help?

set theInput to POSIX path of (choose file with prompt "Choose CMYK file")
set theOutput to POSIX path of (choose file name default name "Untitled.tif")
set theImage to current application's NSImage's alloc()'s initWithContentsOfFile_(theInput)
set imageRep to theImage's representations()'s objectAtIndex_(0)
set targetSpace to current application's NSColorSpace's sRGBColorSpace()
set newImage to imageRep's bitmapImageRepByConvertingToColorSpace_renderingIntent_(targetSpace, current application's NSColorRenderingIntentPerceptual)
set tiffData to newImage's TIFFRepresentation()
tiffData's writeToFile_atomically_(theOutput, true)

Or doing it with ASObjC Runner:

script convertImage
	set {theInput, theOutput} to current application's NSApp's passedValue() as list
	set theImage to current application's NSImage's alloc()'s initWithContentsOfFile_(theInput)
	set imageRep to theImage's representations()'s objectAtIndex_(0)
	set targetSpace to current application's NSColorSpace's sRGBColorSpace()
	set newImage to imageRep's bitmapImageRepByConvertingToColorSpace_renderingIntent_(targetSpace, current application's NSColorRenderingIntentPerceptual)
	set tiffData to newImage's TIFFRepresentation()
	set theResult to tiffData's writeToFile_atomically_(theOutput, true)
	return theResult
end script

set theInput to POSIX path of (choose file with prompt "Choose CMYK file")
set theOutput to POSIX path of (choose file name default name "Untitled.tif")
tell application id "au.com.myriad-com.ASObjC-Runner" -- ASObjC Runner.app
	-- success will return true
	set theResult to run the script {convertImage} passing {theInput, theOutput} with response
end tell

Edited to fix code as per message below.

Hi Shane,

thanks for the code. When I create a Asoc app and run it I receive this error:

cmyk-rgb[673:403] *** -[AppDelegate converti:]: -[NSImage bitmapImageRepByConvertingToColorSpace:renderingIntent:]: unrecognized selector sent to instance 0x1006f7740 (error -10000)

I tried with both CMYK .jpg and .tif files as input.

I put all the code in a handler called converti_(sender) connected to a simple button just to try.

Ame

Sorry – when I translated from Objective-C I left a line out. The relevant code should be:

set theImage to current application's NSImage's alloc()'s initWithContentsOfFile_(theInput)
set imageRep to theImage's representations()'s objectAtIndex_(0)
set targetSpace to current application's NSColorSpace's sRGBColorSpace()
set newImage to imageRep's bitmapImageRepByConvertingToColorSpace_renderingIntent_(targetSpace, current application's NSColorRenderingIntentPerceptual)
set tiffData to newImage's TIFFRepresentation()
tiffData's writeToFile_atomically_(theOutput, true)

Hi Shane it workssssss ;-))))))

Many many thanks.

Sorry for resurrecting an old topic, but I am wondering what the JPEG equivalent to TIFFRepresentation might be? I tried JPEGRepresentation, jpegRepresentation, NSJPEGRepresentation, NSjpegRepresentation, and they all give me an error of “Unrecognized Selector”.

Bonus question, is there an ApplescriptObjC way of reading the chosen files current color space or should I just use Image Events for that?

Thanks!

Today you’d re-write it like this:

use AppleScript version "2.4" -- 10.11 or later
use framework "Foundation"
use framework "AppKit"
use scripting additions

set theInput to (choose file with prompt "Choose CMYK file")
set theOutput to (choose file name default name "Untitled.jpg")
set theImage to current application's NSImage's alloc()'s initWithContentsOfURL:theInput
set imageRep to theImage's representations()'s objectAtIndex:0
set targetSpace to current application's NSColorSpace's sRGBColorSpace()
set bitmapRep to imageRep's bitmapImageRepByConvertingToColorSpace:targetSpace renderingIntent:(current application's NSColorRenderingIntentPerceptual)
set theProps to current application's NSDictionary's dictionaryWithObjects:{1.0, true} forKeys:{current application's NSImageCompressionFactor, current application's NSImageProgressive}
set jpegData to bitmapRep's representationUsingType:(current application's NSJPEGFileType) |properties|:theProps
jpegData's writeToURL:theOutput atomically:true


Use the relevant part above to get bitmap image rep, and then:

bitmapRep's colorSpaceName() as text

So when I add the line above in my script at the bottom before the final “writeToURL” like this:

set colorSpace to bitmapRep's colorSpaceName() as text

The script always comes back with “NSDeviceCMYKColorSpace” no matter if the image is RGB or CMYK.

Am I doing something wrong?

And thank you Shane for that code, that was terrific of you!

It’s returning NSCalibratedRGBColorSpace here.