Unsharp Mask with Core Image or other


any example about how I can apply Unsharp Mask to a tiff or Jpeg file?



this is an example for a jpeg image
change the numeric values in the inputRadius and inputIntensity lines to the values you need

Caution: The script overwrites the original file on disk

property filePath : "/path/to/image.jpg"

set fileURL to current application's |NSURL|'s fileURLWithPath_(filePath)
set unsharpMaskImage to current application's CIImage's imageWithContentsOfURL_(fileURL)
set unsharpMaskFilter to current application's CIFilter's filterWithName_("CIUnsharpMask")
unsharpMaskFilter's setDefaults()
unsharpMaskFilter's setValue_forKey_(unsharpMaskImage, current application's kCIInputImageKey)
unsharpMaskFilter's setValue_forKey_(2.0, "inputRadius")
unsharpMaskFilter's setValue_forKey_(3.0, "inputIntensity")
set unsharpMaskOutputImage to unsharpMaskFilter's valueForKey_("outputImage")
set bitmapRep to current application's NSBitmapImageRep's alloc()'s initWithCIImage_(unsharpMaskOutputImage)
set imageData to bitmapRep's representationUsingType_properties_(current application's NSJPEGFileType, missing value)
imageData's writeToURL_atomically_(fileURL, true)

Much appreciated. Thanks. You are Cocoa Guru ;-))))

Hi Stefan,

I see that the routine discard all metadata info. This is OK me because JPEG for Web should have not Info IPTC or Exif.
I modified the routine using the “CISharpenLuminance” that is much better (should work only on L channel of Lab)

What about convert color to standard sRGB?
I see that Lab values are respected compared to source files, but processed images are assigned to Monitor profile.

At page 58 of CoreImage PDF Apple say:

The conversion to and from sRGB adds to filter complexity, and requires Core Image to apply these equations:
rgb = mix(rgb.0.0774, pow(rgb0.9479 + 0.05213, 2.4), step(0.04045, rgb))
rgb = mix(rgb12.92, pow(rgb
0.4167) * 1.055 - 0.055, step(0.00313, rgb))

But sincerely I don’t know where to start…


Sorry, I have no idea about this color space stuff