图像处理算法之图像暗角特效
生活随笔
收集整理的這篇文章主要介紹了
图像处理算法之图像暗角特效
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
? ? ? ?基本所有圖像美化app都有該特效,有的app叫暈影效果,有的app叫暗角效果,其實就是以圖像為中心,提高圖像四角的亮度或者降低亮度。為圖像四角提高亮度的不多,更多的還是給圖像增加暗角效果,以突出圖像主體。 尤其是很多lomo濾鏡,基本都會加一個暗角。那么暗角是怎么實現的呢,看似很簡單,但真做到ps般色調過渡自然、平滑,看著舒服,還是需要一番計算與調試的。算法總體上沒有復雜原理與計算,看代碼基本就明白了。
? ? ? ?下面是相關示例代碼(亮角: strength范圍為[0.0f, 1.0f], 暗角: strength范圍為[-1.0f, 0.0f]):
void ImageVignetting(BMPINFO *pSrcBitmap, float strength)
{int width = pSrcBitmap->lWidth;int height = pSrcBitmap->lHeight;float radio = 0.0;float maxLen = (float)MAX(width, height);float cx = maxLen * 0.5f;float cy = maxLen * 0.5f;float maxDist = cx*cx + cy*cy;uchar* pSrcData = pSrcBitmap->pPlane[0];if (strength > 0.0f){// 亮角for (int i = 0; i < height; i++){for (int j = 0; j < width; j++, pSrcData += 4){float nx = (float)maxLen * j / width;float ny = (float)maxLen * i / height;float curDist = (nx - cx)*(nx - cx) + (ny - cy)*(ny - cy);radio = curDist / maxDist;// radio *= radio;radio *= strength;pSrcData[BLUE] = (uchar)CLAMP0255(pSrcData[BLUE]*(1.0f - radio) + SCREEN_XY(pSrcData[BLUE], 230)*radio);pSrcData[GREEN] = (uchar)CLAMP0255(pSrcData[GREEN]*(1.0f - radio) + SCREEN_XY(pSrcData[GREEN], 230)*radio);pSrcData[RED] = (uchar)CLAMP0255(pSrcData[RED]*(1.0f - radio) + SCREEN_XY(pSrcData[RED], 230)*radio);}}}else{// 暗角for (int i = 0; i < height; i++){for (int j = 0; j < width; j++, pSrcData += 4){float nx = (float)maxLen * j / width;float ny = (float)maxLen * i / height;float curDist = (nx - cx)*(nx - cx) + (ny - cy)*(ny - cy);radio = curDist / maxDist;// radio *= radio;radio *= strength;radio = 1.0f + radio;pSrcData[BLUE] = (uchar)CLAMP0255(pSrcData[BLUE]*radio);pSrcData[GREEN] = (uchar)CLAMP0255(pSrcData[GREEN]*radio);pSrcData[RED] = (uchar)CLAMP0255(pSrcData[RED]*radio);}}}
}? ? ? ?下面是效果圖:
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??
總結
以上是生活随笔為你收集整理的图像处理算法之图像暗角特效的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: WEBGIS开发 CityEngine使
- 下一篇: 飞行堡垒FN+F5风扇调节失灵怎么办?