目錄
- 一.簡介
- 二.效果演示
- 三.原始碼下載
- 四.猜你喜歡
零基礎 OpenGL (ES) 學習路線推薦 : OpenGL (ES) 學習目錄 >> OpenGL ES 基礎
零基礎 OpenGL (ES) 學習路線推薦 : OpenGL (ES) 學習目錄 >> OpenGL ES 轉場
零基礎 OpenGL (ES) 學習路線推薦 : OpenGL (ES) 學習目錄 >> OpenGL ES 特效
零基礎 OpenGL (ES) 學習路線推薦 : OpenGL (ES) 學習目錄 >> OpenGL ES 函式
零基礎 OpenGL (ES) 學習路線推薦 : OpenGL (ES) 學習目錄 >> OpenGL ES GPUImage 使用
零基礎 OpenGL (ES) 學習路線推薦 : OpenGL (ES) 學習目錄 >> OpenGL ES GLSL 編程
一.簡介
GPUImage 共 125 個濾鏡, 分為四類
1、Color adjustments : 31 filters , 顏色處理相關
2、Image processing : 40 filters , 影像處理相關.
3、Blending modes : 29 filters , 混合模式相關.
4、Visual effects : 25 filters , 視覺效果相關.
GPUImageThresholdedNonMaximumSuppressionFilter屬于 GPUImage 影像視覺效果相關,用來處理**影像影像顯示亮度最高的像素,其他為黑效果**,相比于 GPUImageNonMaximumSuppressionFilter ,GPUImageThresholdedNonMaximumSuppressionFilter像素丟失更多,shader 原始碼如下:
/******************************************************************************************/
//@Author:猿說編程
//@Blog(個人博客地址): www.codersrc.com
//@File:IOS – OpenGL ES GPUImage 影像顯示亮度最高的像素,其他為黑 GPUImageThresholdedNonMaximumSuppressionFilter
//@Time:2022/06/21 06:30
//@Motto:不積跬步無以至千里,不積小流無以成江海,程式人生的精彩需要堅持不懈地積累!
/******************************************************************************************/
#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE
NSString *const kGPUImageThresholdedNonMaximumSuppressionFragmentShaderString = SHADER_STRING
(
uniform sampler2D inputImageTexture;
varying highp vec2 textureCoordinate;
varying highp vec2 leftTextureCoordinate;
varying highp vec2 rightTextureCoordinate;
varying highp vec2 topTextureCoordinate;
varying highp vec2 topLeftTextureCoordinate;
varying highp vec2 topRightTextureCoordinate;
varying highp vec2 bottomTextureCoordinate;
varying highp vec2 bottomLeftTextureCoordinate;
varying highp vec2 bottomRightTextureCoordinate;
uniform lowp float threshold;
void main()
{
lowp float bottomColor = texture2D(inputImageTexture, bottomTextureCoordinate).r;
lowp float bottomLeftColor = texture2D(inputImageTexture, bottomLeftTextureCoordinate).r;
lowp float bottomRightColor = texture2D(inputImageTexture, bottomRightTextureCoordinate).r;
lowp vec4 centerColor = texture2D(inputImageTexture, textureCoordinate);
lowp float leftColor = texture2D(inputImageTexture, leftTextureCoordinate).r;
lowp float rightColor = texture2D(inputImageTexture, rightTextureCoordinate).r;
lowp float topColor = texture2D(inputImageTexture, topTextureCoordinate).r;
lowp float topRightColor = texture2D(inputImageTexture, topRightTextureCoordinate).r;
lowp float topLeftColor = texture2D(inputImageTexture, topLeftTextureCoordinate).r;
// Use a tiebreaker for pixels to the left and immediately above this one
lowp float multiplier = 1.0 - step(centerColor.r, topColor);
multiplier = multiplier * (1.0 - step(centerColor.r, topLeftColor));
multiplier = multiplier * (1.0 - step(centerColor.r, leftColor));
multiplier = multiplier * (1.0 - step(centerColor.r, bottomLeftColor));
lowp float maxValue = https://www.cnblogs.com/shuopython/archive/2022/07/11/max(centerColor.r, bottomColor);
maxValue = max(maxValue, bottomRightColor);
maxValue = max(maxValue, rightColor);
maxValue = max(maxValue, topRightColor);
lowp float finalValue = centerColor.r * step(maxValue, centerColor.r) * multiplier;
finalValue = step(threshold, finalValue);
gl_FragColor = vec4(finalValue, finalValue, finalValue, 1.0);
//
// gl_FragColor = vec4((centerColor.rgb * step(maxValue, step(threshold, centerColor.r)) * multiplier), 1.0);
}
);
NSString *const kGPUImageThresholdedNonMaximumSuppressionPackedColorspaceFragmentShaderString = SHADER_STRING
(
uniform sampler2D inputImageTexture;
varying highp vec2 textureCoordinate;
varying highp vec2 leftTextureCoordinate;
varying highp vec2 rightTextureCoordinate;
varying highp vec2 topTextureCoordinate;
varying highp vec2 topLeftTextureCoordinate;
varying highp vec2 topRightTextureCoordinate;
varying highp vec2 bottomTextureCoordinate;
varying highp vec2 bottomLeftTextureCoordinate;
varying highp vec2 bottomRightTextureCoordinate;
uniform lowp float threshold;
uniform highp float texelWidth;
uniform highp float texelHeight;
highp float encodedIntensity(highp vec3 sourceColor)
{
return (sourceColor.b * 256.0 * 256.0 + sourceColor.g * 256.0 + sourceColor.r);
}
void main()
{
highp float bottomColor = encodedIntensity(texture2D(inputImageTexture, bottomTextureCoordinate).rgb);
highp float bottomLeftColor = encodedIntensity(texture2D(inputImageTexture, bottomLeftTextureCoordinate).rgb);
highp float bottomRightColor = encodedIntensity(texture2D(inputImageTexture, bottomRightTextureCoordinate).rgb);
highp float centerColor = encodedIntensity(texture2D(inputImageTexture, textureCoordinate).rgb);
highp float leftColor = encodedIntensity(texture2D(inputImageTexture, leftTextureCoordinate).rgb);
highp float rightColor = encodedIntensity(texture2D(inputImageTexture, rightTextureCoordinate).rgb);
highp float topColor = encodedIntensity(texture2D(inputImageTexture, topTextureCoordinate).rgb);
highp float topRightColor = encodedIntensity(texture2D(inputImageTexture, topRightTextureCoordinate).rgb);
highp float topLeftColor = encodedIntensity(texture2D(inputImageTexture, topLeftTextureCoordinate).rgb);
highp float secondStageColor1 = encodedIntensity(texture2D(inputImageTexture, textureCoordinate + vec2(-2.0 * texelWidth, -2.0 * texelHeight)).rgb);
highp float secondStageColor2 = encodedIntensity(texture2D(inputImageTexture, textureCoordinate + vec2(-2.0 * texelWidth, -1.0 * texelHeight)).rgb);
highp float secondStageColor3 = encodedIntensity(texture2D(inputImageTexture, textureCoordinate + vec2(-2.0 * texelWidth, 0.0)).rgb);
highp float secondStageColor4 = encodedIntensity(texture2D(inputImageTexture, textureCoordinate + vec2(-2.0 * texelWidth, 1.0 * texelHeight)).rgb);
highp float secondStageColor5 = encodedIntensity(texture2D(inputImageTexture, textureCoordinate + vec2(-2.0 * texelWidth, 2.0 * texelHeight)).rgb);
highp float secondStageColor6 = encodedIntensity(texture2D(inputImageTexture, textureCoordinate + vec2(-1.0 * texelWidth, 2.0 * texelHeight)).rgb);
highp float secondStageColor7 = encodedIntensity(texture2D(inputImageTexture, textureCoordinate + vec2(0.0, 2.0 * texelHeight)).rgb);
highp float secondStageColor8 = encodedIntensity(texture2D(inputImageTexture, textureCoordinate + vec2(1.0 * texelWidth, 2.0 * texelHeight)).rgb);
highp float thirdStageColor1 = encodedIntensity(texture2D(inputImageTexture, textureCoordinate + vec2(-1.0 * texelWidth, -2.0 * texelHeight)).rgb);
highp float thirdStageColor2 = encodedIntensity(texture2D(inputImageTexture, textureCoordinate + vec2(0.0, -2.0 * texelHeight)).rgb);
highp float thirdStageColor3 = encodedIntensity(texture2D(inputImageTexture, textureCoordinate + vec2(1.0 * texelWidth, -2.0 * texelHeight)).rgb);
highp float thirdStageColor4 = encodedIntensity(texture2D(inputImageTexture, textureCoordinate + vec2(2.0 * texelWidth, -2.0 * texelHeight)).rgb);
highp float thirdStageColor5 = encodedIntensity(texture2D(inputImageTexture, textureCoordinate + vec2(2.0 * texelWidth, -1.0 * texelHeight)).rgb);
highp float thirdStageColor6 = encodedIntensity(texture2D(inputImageTexture, textureCoordinate + vec2(2.0 * texelWidth, 0.0)).rgb);
highp float thirdStageColor7 = encodedIntensity(texture2D(inputImageTexture, textureCoordinate + vec2(2.0 * texelWidth, 1.0 * texelHeight)).rgb);
highp float thirdStageColor8 = encodedIntensity(texture2D(inputImageTexture, textureCoordinate + vec2(2.0 * texelWidth, 2.0 * texelHeight)).rgb);
// Use a tiebreaker for pixels to the left and immediately above this one
highp float multiplier = 1.0 - step(centerColor, topColor);
multiplier = multiplier * (1.0 - step(centerColor, topLeftColor));
multiplier = multiplier * (1.0 - step(centerColor, leftColor));
multiplier = multiplier * (1.0 - step(centerColor, bottomLeftColor));
multiplier = multiplier * (1.0 - step(centerColor, secondStageColor1));
multiplier = multiplier * (1.0 - step(centerColor, secondStageColor2));
multiplier = multiplier * (1.0 - step(centerColor, secondStageColor3));
multiplier = multiplier * (1.0 - step(centerColor, secondStageColor4));
multiplier = multiplier * (1.0 - step(centerColor, secondStageColor5));
multiplier = multiplier * (1.0 - step(centerColor, secondStageColor6));
multiplier = multiplier * (1.0 - step(centerColor, secondStageColor7));
multiplier = multiplier * (1.0 - step(centerColor, secondStageColor8));
highp float maxValue = max(centerColor, bottomColor);
maxValue = max(maxValue, bottomRightColor);
maxValue = max(maxValue, rightColor);
maxValue = max(maxValue, topRightColor);
maxValue = max(maxValue, thirdStageColor1);
maxValue = max(maxValue, thirdStageColor2);
maxValue = max(maxValue, thirdStageColor3);
maxValue = max(maxValue, thirdStageColor4);
maxValue = max(maxValue, thirdStageColor5);
maxValue = max(maxValue, thirdStageColor6);
maxValue = max(maxValue, thirdStageColor7);
maxValue = max(maxValue, thirdStageColor8);
highp float midValue = centerColor * step(maxValue, centerColor) * multiplier;
highp float finalValue = step(threshold, midValue);
gl_FragColor = vec4(finalValue * centerColor, topLeftColor, topRightColor, topColor);
}
);
#else
NSString *const kGPUImageThresholdedNonMaximumSuppressionFragmentShaderString = SHADER_STRING
(
uniform sampler2D inputImageTexture;
varying vec2 textureCoordinate;
varying vec2 leftTextureCoordinate;
varying vec2 rightTextureCoordinate;
varying vec2 topTextureCoordinate;
varying vec2 topLeftTextureCoordinate;
varying vec2 topRightTextureCoordinate;
varying vec2 bottomTextureCoordinate;
varying vec2 bottomLeftTextureCoordinate;
varying vec2 bottomRightTextureCoordinate;
uniform float threshold;
void main()
{
float bottomColor = texture2D(inputImageTexture, bottomTextureCoordinate).r;
float bottomLeftColor = texture2D(inputImageTexture, bottomLeftTextureCoordinate).r;
float bottomRightColor = texture2D(inputImageTexture, bottomRightTextureCoordinate).r;
vec4 centerColor = texture2D(inputImageTexture, textureCoordinate);
float leftColor = texture2D(inputImageTexture, leftTextureCoordinate).r;
float rightColor = texture2D(inputImageTexture, rightTextureCoordinate).r;
float topColor = texture2D(inputImageTexture, topTextureCoordinate).r;
float topRightColor = texture2D(inputImageTexture, topRightTextureCoordinate).r;
float topLeftColor = texture2D(inputImageTexture, topLeftTextureCoordinate).r;
// Use a tiebreaker for pixels to the left and immediately above this one
float multiplier = 1.0 - step(centerColor.r, topColor);
multiplier = multiplier * (1.0 - step(centerColor.r, topLeftColor));
multiplier = multiplier * (1.0 - step(centerColor.r, leftColor));
multiplier = multiplier * (1.0 - step(centerColor.r, bottomLeftColor));
float maxValue = max(centerColor.r, bottomColor);
maxValue = max(maxValue, bottomRightColor);
maxValue = max(maxValue, rightColor);
maxValue = max(maxValue, topRightColor);
float finalValue = centerColor.r * step(maxValue, centerColor.r) * multiplier;
finalValue = step(threshold, finalValue);
gl_FragColor = vec4(finalValue, finalValue, finalValue, 1.0);
//
// gl_FragColor = vec4((centerColor.rgb * step(maxValue, step(threshold, centerColor.r)) * multiplier), 1.0);
}
);
NSString *const kGPUImageThresholdedNonMaximumSuppressionPackedColorspaceFragmentShaderString = SHADER_STRING
(
uniform sampler2D inputImageTexture;
varying vec2 textureCoordinate;
varying vec2 leftTextureCoordinate;
varying vec2 rightTextureCoordinate;
varying vec2 topTextureCoordinate;
varying vec2 topLeftTextureCoordinate;
varying vec2 topRightTextureCoordinate;
varying vec2 bottomTextureCoordinate;
varying vec2 bottomLeftTextureCoordinate;
varying vec2 bottomRightTextureCoordinate;
uniform float threshold;
void main()
{
float bottomColor = texture2D(inputImageTexture, bottomTextureCoordinate).r;
float bottomLeftColor = texture2D(inputImageTexture, bottomLeftTextureCoordinate).r;
float bottomRightColor = texture2D(inputImageTexture, bottomRightTextureCoordinate).r;
vec4 centerColor = texture2D(inputImageTexture, textureCoordinate);
float leftColor = texture2D(inputImageTexture, leftTextureCoordinate).r;
float rightColor = texture2D(inputImageTexture, rightTextureCoordinate).r;
float topColor = texture2D(inputImageTexture, topTextureCoordinate).r;
float topRightColor = texture2D(inputImageTexture, topRightTextureCoordinate).r;
float topLeftColor = texture2D(inputImageTexture, topLeftTextureCoordinate).r;
// Use a tiebreaker for pixels to the left and immediately above this one
float multiplier = 1.0 - step(centerColor.r, topColor);
multiplier = multiplier * (1.0 - step(centerColor.r, topLeftColor));
multiplier = multiplier * (1.0 - step(centerColor.r, leftColor));
multiplier = multiplier * (1.0 - step(centerColor.r, bottomLeftColor));
float maxValue = max(centerColor.r, bottomColor);
maxValue = max(maxValue, bottomRightColor);
maxValue = max(maxValue, rightColor);
maxValue = max(maxValue, topRightColor);
float finalValue = centerColor.r * step(maxValue, centerColor.r) * multiplier;
finalValue = step(threshold, finalValue);
gl_FragColor = vec4(finalValue, finalValue, finalValue, 1.0);
//
// gl_FragColor = vec4((centerColor.rgb * step(maxValue, step(threshold, centerColor.r)) * multiplier), 1.0);
}
);
#endif
二.效果演示
使用 GPUImageThresholdedNonMaximumSuppressionFilter 完成影像顯示亮度最高的像素,其他為黑,原圖如下:

使用 GPUImageThresholdedNonMaximumSuppressionFilter 完成影像顯示亮度最高的像素,其他為黑****,效果如下:

三.原始碼下載
OpenGL ES Demo 下載地址 : IOS – OpenGL ES GPUImage 影像顯示亮度最高的像素,其他為黑 GPUImageThresholdedNonMaximumSuppressionFilter

四.猜你喜歡
- IOS – OPenGL ES 設定影像亮度 GPUImageBrightnessFilter
- IOS – OPenGL ES 調節影像曝光度 GPUImageExposureFilter
- IOS – OpenGL ES 調節影像對比度 GPUImageContrastFilter
- IOS – OPenGL ES 調節影像飽和度 GPUImageSaturationFilter
- IOS – OPenGL ES 調節影像伽馬線 GPUImageGammaFilter
- IOS – OpenGL ES 調節影像反色 GPUImageColorInvertFilter
- IOS – OpenGL ES 調節影像褐色 GPUImageSepiaFilter
- IOS – OpenGL ES 調節影像灰色 GPUImageGrayscaleFilter
- IOS – OpenGL ES 調節影像 RGB 通道 GPUImageRGBFilter
- IOS – OpenGL ES 調節影像不透明度 GPUImageOpacityFilter
- IOS – OpenGL ES 調節影像陰影 GPUImageHighlightShadowFilter
- IOS – OpenGL ES 調節影像色彩替換 GPUImageFalseColorFilter
- GPUImage – 色彩直方圖 GPUImageHistogramFilter
- GPUImage – 色彩直方圖 GPUImageHistogramGenerator
- GPUImage – 像素平均色值 GPUImageAverageColor
- GPUImage – 亮度平均 GPUImageLuminosity
- IOS – OpenGL ES 調節影像色度 GPUImageHueFilter
- IOS – OpenGL ES 指定顏色摳圖 GPUImageChromaKeyFilter
- IOS – OpenGL ES 調節影像白平衡/色溫 GPUImageWhiteBalanceFilter
- IOS – OpenGL ES 設定影像 lookup 濾鏡 GPUImageLookupFilter
- IOS – OpenGL ES 設定影像濾鏡 GPUImageAmatorkaFilter
- IOS – OpenGL ES 設定影像濾鏡 GPUImageSoftEleganceFilter
- IOS – OpenGL ES 設定影像銳化 GPUImageSharpenFilter
- IOS – OpenGL ES 繪制十字 GPUImageCrosshairGenerator
- IOS – OpenGL ES 繪制線條 GPUImageLineGenerator
- IOS – OpenGL ES 設定影像黑白燥點 GPUImageLocalBinaryPatternFilter
- IOS – OpenGL ES 設定影像卡通效果(黑色粗線描邊) GPUImageToonFilter
- IOS – OpenGL ES 桑原濾波/水粉畫模糊效果 GPUImageKuwaharaFilter
- IOS – OpenGL ES 黑白馬賽克效果 GPUImageMosaicFilter
- IOS – OpenGL ES 像素化馬賽克效果 GPUImagePixellateFilter
- IOS – OpenGL ES 同心圓像素化馬賽克效果 GPUImagePolarPixel
- IOS – OpenGL ES 黑白網狀效果 GPUImageCrosshatchFilter
- IOS – OpenGL ES 色彩丟失/模糊效果 GPUImageColorPackingFilter
- IOS – OpenGL ES 影像暈影 GPUImageVignetteFilter
- IOS – OpenGL ES 影像漩渦 GPUImageSwirlFilter
- IOS – OpenGL ES 影像魚眼擴散效果 GPUImageBulgeDistortionFilter
- IOS – OpenGL ES 影像魚眼移動效果 GPUImageBulgeDistortionFilter
- IOS – OpenGL ES 影像凹面鏡移動效果 GPUImagePinchDistortionFilter
- IOS – OpenGL ES 影像凹面鏡放大效果 GPUImagePinchDistortionFilter
- IOS – OpenGL ES 影像哈哈鏡效果 GPUImageStretchDistortionFilter
- IOS – OpenGL ES 影像水晶球效果 GPUImageGlassSphereFilter
- IOS – OpenGL ES 影像球形折射 GPUImageSphereRefractionFilter
- IOS – OpenGL ES 影像色調分離噪點效果 GPUImagePosterizeFilter
- IOS – OpenGL ES 影像 CGA 色彩濾鏡 GPUImageCGAColorspaceFilter
- IOS – OpenGL ES 影像柏林噪點/花邊噪點 GPUImagePerlinNoiseFilter
- IOS – OpenGL ES 影像加亮邊緣 GPUImage3x3ConvolutionFilter
- IOS – OpenGL ES 影像浮雕 3d 效果 GPUImageEmbossFilter
- IOS – OpenGL ES 影像馬賽克圓點 GPUImagePolkaDotFilter
- IOS – OpenGL ES 影像侵蝕邊緣黑白模糊 GPUImageErosionFilter
- IOS – OpenGL ES 影像侵蝕邊緣色彩模糊 GPUImageRGBErosionFilter
- IOS – OpenGL ES 影像擴展邊緣黑白模糊 GPUImageDilationFilter
- IOS – OpenGL ES 影像擴展邊緣彩色模糊 GPUImageRGBDilationFilter
- IOS – OpenGL ES GPUImage 黑白色調模糊 GPUImageOpeningFilter
- IOS – OpenGL ES GPUImage 彩色模糊 GPUImageRGBOpeningFilter
- IOS – OpenGL ES GPUImage 影像黑白色調模糊/暗色提亮 GPUImageClosingFilter
- IOS – OpenGL ES GPUImage 影像彩色調模糊/暗色提亮 GPUImageRGBClosingFilter
- IOS – OpenGL ES GPUImage 影像 Lanczos 重取樣模糊效果 GPUImageLanczosResamplingFilter
- IOS – OpenGL ES GPUImage 影像顯示亮度最高的像素,其他為黑 GPUImageNonMaximumSuppressionFilter
- IOS – OpenGL ES GPUImage 影像顯示亮度最高的像素,其他為黑 GPUImageThresholdedNonMaximumSuppressionFilter
本文由博客 - 猿說編程 猿說編程 發布!
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/498591.html
標籤:其他
