負片(negative film)即為普遍的底片型式,同反轉片屬拍攝用底片,為照相、電影等攝影所使用取得負像(negative)的感光材料。
實際即是明暗與色調皆與原來景物相反的負像影像。
因此其演算邏輯相當單純,即是將該顏色的最大值減去目前顏色的值量即可。
P = COLOR_MAX - COLOR
灰階影像相對單純,即是255 - 灰階值即可,其實驗結果如下圖 :
而全彩影像則是所有顏色皆經由相同的演算邏輯 ( 最大值減去當前顏色值 ) ,其實驗成果如下圖 :
C#
private static Bitmap negative(Bitmap srcBitmap)
{
int width = srcBitmap.Width;
int height = srcBitmap.Height;
System.IntPtr srcScan, dstScan;
BitmapData srcBmData, dstBmData;
Bitmap dstBitmap =ImageExtract.InitPonitMethod(srcBitmap, width, height, out srcScan, out dstScan, out srcBmData, out dstBmData);
unsafe //啟動不安全代碼
{
byte* srcP = (byte*)srcScan;
byte* dstP = (byte*)dstScan;
int srcOffset = srcBmData.Stride - width * 3;
int dstOffset = dstBmData.Stride - width * 3;
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++, srcP += 3, dstP += 3)
{
*dstP = (byte)(COLOR_SIZE_RANGE - srcP[0]); //blue
*(dstP + 1) = (byte)(COLOR_SIZE_RANGE - srcP[1]); //green
*(dstP + 2) = (byte)(COLOR_SIZE_RANGE - srcP[2]); //red
}
srcP += srcOffset;
dstP += dstOffset;
}
}
srcBitmap.UnlockBits(srcBmData);
dstBitmap.UnlockBits(dstBmData);
return dstBitmap;
}
完整專案 : https://github.com/Lung-Yu/ImageToolBox/blob/master/ImageProcessToolBox/Negative.cs
文章標籤
全站熱搜