Hiren Patel
Hiren Patel

Reputation: 69

Output Image gives NULL after applying CIFilter

I want to give effects on the image with CIImage framework, and when i set parameters for that the out put image shows blank image.

Any suggestions?

Code is used to apply filter is as follows :

- (IBAction)filterImage:(id)sender {

    CIImage *rawImageData;
    rawImageData =[[CIImage alloc] initWithImage:self.imageView.image];

    CIFilter *filter = [CIFilter filterWithName:@"CIDepthOfField"];
    [filter setDefaults];

    [filter setValue:rawImageData forKey:@"inputImage"];

    [filter setValue:[CIVector vectorWithCGPoint:CGPointMake(50, 50)]
              forKey:@"inputPoint1"];

    [filter setValue:[CIVector vectorWithCGPoint:CGPointMake(100, 100)]
              forKey:@"inputPoint2"];

    [filter setValue:[NSNumber numberWithFloat:15.00]
              forKey:@"inputSaturation"];    

    [filter setValue:[NSNumber numberWithFloat:15.00]
              forKey:@"inputUnsharpMaskRadius"];

    [filter setValue:[NSNumber numberWithFloat:15.70]
              forKey:@"inputRadius"];



    CIImage *filteredImageData = [filter valueForKey:@"outputImage"];

    UIImage *filteredImage = [UIImage imageWithCIImage:filteredImageData];
    self.imageView.image = filteredImage;


}

Upvotes: 0

Views: 2325

Answers (5)

Khalbaevdm
Khalbaevdm

Reputation: 1

Because CIDepthOfField

Available in OS X v10.6 and later.

(c) Apple documentation

Filter CIDepthOfField is NULL in iOS device

Upvotes: 0

Sinisa Drpa
Sinisa Drpa

Reputation: 917

The problem is in this line:

[filter setValue:[CIVector vectorWithCGPoint:CGPointMake(100, 100)]
          forKey:@"inputPoint2"];

There is no attribute (key) @"inputPoint2" in CIDepthOfField.

Documentation: https://developer.apple.com/library/mac/documentation/graphicsimaging/reference/CoreImageFilterReference/Reference/reference.html#//apple_ref/doc/filter/ci/CIDepthOfField is wrong.

Use @"inputPoint0" and @"inputPoint1" and it will work.

To inspect CIFiter attributes use:

[sampleFilterObject attributes]

Upvotes: 0

sketchyTech
sketchyTech

Reputation: 5906

The first thing, which Xcode should warn you about anyway, is that you are using initWithImage: when you should be using initWithCIImage: (I'm guessing that's a typo). Second you should be converting the UIImage returned by self.imageView.image into a CIImage - see How to Convert UIImage to CIImage and vice versa

Upvotes: 0

Arun
Arun

Reputation: 3404

These are available iOS filters, we can use

NSArray *filterNamesArray = [CIFilter filterNamesInCategories:[NSArray arrayWithObject:kCICategoryBuiltIn]];

  $1 = 0x071b8560 <__NSArrayI 0x71b8560>(
    CIAdditionCompositing,
    CIAffineClamp,
    CIAffineTile,
    CIAffineTransform,
    CIBarsSwipeTransition,
    CIBlendWithMask,
    CIBloom,
    CIBumpDistortion,
    CIBumpDistortionLinear,
    CICheckerboardGenerator,
    CICircleSplashDistortion,
    CICircularScreen,
    CIColorBlendMode,
    CIColorBurnBlendMode,
    CIColorControls,
    CIColorCube,
    CIColorDodgeBlendMode,
    CIColorInvert,
    CIColorMap,
    CIColorMatrix,
    CIColorMonochrome,
    CIColorPosterize,
    CIConstantColorGenerator,
    CICopyMachineTransition,
    CICrop,
    CIDarkenBlendMode,
    CIDifferenceBlendMode,
    CIDisintegrateWithMaskTransition,
    CIDissolveTransition,
    CIDotScreen,
    CIEightfoldReflectedTile,
    CIExclusionBlendMode,
    CIExposureAdjust,
    CIFalseColor,
    CIFlashTransition,
    CIFourfoldReflectedTile,
    CIFourfoldRotatedTile,
    CIFourfoldTranslatedTile,
    CIGammaAdjust,
    CIGaussianBlur,
    CIGaussianGradient,
    CIGlideReflectedTile,
    CIGloom,
    CIHardLightBlendMode,
    CIHatchedScreen,
    CIHighlightShadowAdjust,
    CIHoleDistortion,
    CIHueAdjust,
    CIHueBlendMode,
    CILanczosScaleTransform,
    CILightenBlendMode,
    CILightTunnel,
    CILinearGradient,
    CILineScreen,
    CILuminosityBlendMode,
    CIMaskToAlpha,
    CIMaximumComponent,
    CIMaximumCompositing,
    CIMinimumComponent,
    CIMinimumCompositing,
    CIModTransition,
    CIMultiplyBlendMode,
    CIMultiplyCompositing,
    CIOverlayBlendMode,
    CIPinchDistortion,
    CIPixellate,
    CIRadialGradient,
    CIRandomGenerator,
    CISaturationBlendMode,
    CIScreenBlendMode,
    CISepiaTone,
    CISharpenLuminance,
    CISixfoldReflectedTile,
    CISixfoldRotatedTile,
    CISmoothLinearGradient,
    CISoftLightBlendMode,
    CISourceAtopCompositing,
    CISourceInCompositing,
    CISourceOutCompositing,
    CISourceOverCompositing,
    CIStarShineGenerator,
    CIStraightenFilter,
    CIStripesGenerator,
    CISwipeTransition,
    CITemperatureAndTint,
    CIToneCurve,
    CITriangleKaleidoscope,
    CITwelvefoldReflectedTile,
    CITwirlDistortion,
    CIUnsharpMask,
    CIVibrance,
    CIVignette,
    CIVortexDistortion,
    CIWhitePointAdjust
    )

Upvotes: 1

srinivas n
srinivas n

Reputation: 640

Check this link

and try using the following code

  CIImage *filteredImage = [invertColour outputImage];
  UIImage *newImg = [UIImage imageWithCIImage:filteredImage];

Upvotes: 0

Related Questions