新聞中心
目錄
讓客戶滿意是我們工作的目標,不斷超越客戶的期望值來自于我們對這個行業(yè)的熱愛。我們立志把好的技術通過有效、簡單的方式提供給客戶,將通過不懈努力成為客戶在信息化領域值得信任、有價值的長期合作伙伴,公司提供的服務項目有:域名注冊、網(wǎng)站空間、營銷軟件、網(wǎng)站建設、海門網(wǎng)站維護、網(wǎng)站推廣。
- 一.簡介
- 二.效果演示
- 三.源碼下載
- 四.猜你喜歡
零基礎 OpenGL (ES) 學習路線推薦 : OpenGL (ES) 學習目錄 >> OpenGL ES 基礎
零基礎 OpenGL (ES) 學習路線推薦 : OpenGL (ES) 學習目錄 >> OpenGL ES 轉場
零基礎 OpenGL (ES) 學習路線推薦 : OpenGL (ES) 學習目錄 >> OpenGL ES 特效
零基礎 OpenGL (ES) 學習路線推薦 : OpenGL (ES) 學習目錄 >> OpenGL ES 函數(shù)
零基礎 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 = 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 調節(jié)圖像曝光度 GPUImageExposureFilter
- IOS – OpenGL ES 調節(jié)圖像對比度 GPUImageContrastFilter
- IOS – OPenGL ES 調節(jié)圖像飽和度 GPUImageSaturationFilter
- IOS – OPenGL ES 調節(jié)圖像伽馬線 GPUImageGammaFilter
- IOS – OpenGL ES 調節(jié)圖像反色 GPUImageColorInvertFilter
- IOS – OpenGL ES 調節(jié)圖像褐色 GPUImageSepiaFilter
- IOS – OpenGL ES 調節(jié)圖像灰色 GPUImageGrayscaleFilter
- IOS – OpenGL ES 調節(jié)圖像 RGB 通道 GPUImageRGBFilter
- IOS – OpenGL ES 調節(jié)圖像不透明度 GPUImageOpacityFilter
- IOS – OpenGL ES 調節(jié)圖像陰影 GPUImageHighlightShadowFilter
- IOS – OpenGL ES 調節(jié)圖像色彩替換 GPUImageFalseColorFilter
- GPUImage – 色彩直方圖 GPUImageHistogramFilter
- GPUImage – 色彩直方圖 GPUImageHistogramGenerator
- GPUImage – 像素平均色值 GPUImageAverageColor
- GPUImage – 亮度平均 GPUImageLuminosity
- IOS – OpenGL ES 調節(jié)圖像色度 GPUImageHueFilter
- IOS – OpenGL ES 指定顏色摳圖 GPUImageChromaKeyFilter
- IOS – OpenGL ES 調節(jié)圖像白平衡/色溫 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 黑白網(wǎng)狀效果 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
本文由博客 - 猿說編程 猿說編程 發(fā)布!
分享名稱:IOS OpenGL ES GPUImage 圖像顯示亮度最高的像素,其他為黑 GPUImageThresholdedNonMaximumSuppressionFilter
文章地址:http://fisionsoft.com.cn/article/dsoigog.html