OWolf
OWolf

Reputation: 5132

Objective C unsharp mask filter Xcode

What would be the most efficient way to create an unsharp mask filter in Objective C targeting iOS? Would it be best to implement some open source like ImageMagick or build from scratch.

I think the basic formula is generally as follows (please comment if I have not gotten it right).

  1. Duplicate original
  2. Blur duplicate (Gaussian)
  3. blend with original via "difference"
  4. use result to mask original
  5. Increase contrast in the unmasked areas of the original.

Upvotes: 0

Views: 1303

Answers (2)

Wilbur Vandrsmith
Wilbur Vandrsmith

Reputation: 5050

Core Image has the CIUnsharpMask filter built-in, although I'm not sure if it's available on iOS yet. Brad Larson's GPUImage framework also has an unsharp mask filter.

Both methods should be very fast and much easier to implement than cross-compiling ImageMagick or writing your own.

Upvotes: 1

Uswa Naeem
Uswa Naeem

Reputation: 11

(UIImage *)useOfUnsharpMask:(CIImage *)beginImage 
{

    float sliderValue = sharpnessSlider.value;
    CIFilter *filter = [CIFilter filterWithName:@"CIUnsharpMask" keysAndValues:kCIInputImageKey,beginImage,@"inputIntensity",[NSNumber numberWithFloat:sliderValue],@"inputRadius",@2.50, nil];
    CIContext *context = [CIContext contextWithOptions:nil];

    CIImage *outputImage = [filter valueForKey: @"outputImage"];
    UIImage *finalImage = [UIImage imageWithCGImage:[context createCGImage:outputImage fromRect:outputImage.extent]];

    return finalImage;
}

Hope that helps :)

Upvotes: 1

Related Questions