應用銳化工具可以快速聚焦模糊邊緣,提高圖像中某一部位的清晰度或者焦距程度,使圖像特定區域的色彩更加鮮明。 在應用銳化工具時,若勾選器選項欄中的“對所有圖層取樣”覆選框,則可對所有可見圖層中的圖像進行銳化。但一定要適度。銳化不是萬能的,很容易使東西不真實。 在GPUImage中使用GPUImag...
應用銳化工具可以快速聚焦模糊邊緣,提高圖像中某一部位的清晰度或者焦距程度,使圖像特定區域的色彩更加鮮明。 在應用銳化工具時,若勾選器選項欄中的“對所有圖層取樣”覆選框,則可對所有可見圖層中的圖像進行銳化。但一定要適度。銳化不是萬能的,很容易使東西不真實。
在GPUImage中使用GPUImageSharpenFilter類來實現圖像的銳化效果
片段著色
precision highp float; varying highp vec2 textureCoordinate; varying highp vec2 leftTextureCoordinate; varying highp vec2 rightTextureCoordinate; varying highp vec2 topTextureCoordinate; varying highp vec2 bottomTextureCoordinate; varying highp float centerMultiplier; varying highp float edgeMultiplier; uniform sampler2D inputImageTexture; void main() { mediump vec3 textureColor = texture2D(inputImageTexture, textureCoordinate).rgb; mediump vec3 leftTextureColor = texture2D(inputImageTexture, leftTextureCoordinate).rgb; mediump vec3 rightTextureColor = texture2D(inputImageTexture, rightTextureCoordinate).rgb; mediump vec3 topTextureColor = texture2D(inputImageTexture, topTextureCoordinate).rgb; mediump vec3 bottomTextureColor = texture2D(inputImageTexture, bottomTextureCoordinate).rgb; gl_FragColor = vec4((textureColor * centerMultiplier - (leftTextureColor * edgeMultiplier + rightTextureColor * edgeMultiplier + topTextureColor * edgeMultiplier + bottomTextureColor * edgeMultiplier)), texture2D(inputImageTexture, bottomTextureCoordinate).w); }
具體應用
+ (UIImage *)changeValueForSharpenilter:(float)value image:(UIImage *)image { GPUImageSharpenFilter *filter = [[GPUImageSharpenFilter alloc] init]; filter.sharpness = value; [filter forceProcessingAtSize:image.size]; GPUImagePicture *pic = [[GPUImagePicture alloc] initWithImage:image]; [pic addTarget:filter]; [pic processImage]; [filter useNextFrameForImageCapture]; return [filter imageFromCurrentFramebuffer]; }
效果