【发布时间】:2014-05-26 08:05:26
【问题描述】:
您好,我想在我的应用程序中实现对比度过滤器,例如 this link 或 this contrast,但使用颜色矩阵和轨迹栏作为值
我已经找到了它的颜色矩阵
float c = mytrackbar.value * 0.01f //maxTrackbarValue = 100, minTrackbarValue = -100
float t = 0.01f;
cmPicture = new ColorMatrix(new float[][] {
new float[] {c,0,0,0,0},
new float[] {0,c,0,0,0},
new float[] {0,0,c,0,0},
new float[] {0,0,0,1,0},
new float[] {t,t,t,0,1}
});
但结果却大不相同。我尝试更改 ~c~ 中的 0.01f 和 ~t~ 中的 0.01f 值,但它只会给出像亮度这样的结果 (例如:c = mytrackbar.value * 0.04f)
我想知道 ~c~ 和 ~t~ 值是多少以及我应该使用多少个最大和最小范围来创建对比度
更新@Nico
private void myTrackBar_ValueChanged(object sender, EventArgs e) {
imageHandle = imageHandleTemp.Bitmap;
myNumericUpDown.Text = myTrackBar.Value.ToString();
float value = myTrackBar.Value * 0.01f;
Bitmap bmpInverted = new Bitmap(imageHandle.Width, imageHandle.Height);
ImageAttributes ia = new ImageAttributes();
ColorMatrix cmPicture = new ColorMatrix();
float c = value;
float t = 0.01f;
cmPicture = new ColorMatrix(new float[][] {
new float[] {c,0,0,0,0},
new float[] {0,c,0,0,0},
new float[] {0,0,c,0,0},
new float[] {0,0,0,1,0},
new float[] {t,t,t,0,1}
});
ia.SetColorMatrix(cmPicture);
Graphics g = Graphics.FromImage(bmpInverted);
g.DrawImage(imageHandle, new Rectangle(0, 0, imageHandle.Width, imageHandle.Height), 0, 0, imageHandle.Width, imageHandle.Height, GraphicsUnit.Pixel, ia);
g.Dispose();
Image<Bgr, Byte> myImage = new Image<Bgr, byte>(bmpInverted);
imageBoxCamera.Image = myImage;
}
【问题讨论】:
-
请添加代码的相关部分。你如何应用这个矩阵?
-
看看这个link。它说
t = (1.0 - c) / 2.0和c = contrast。所有值都从 0 到 1。 -
@NicoSchertler 请查看我更新的帖子
-
@TaW 我很抱歉,但结果还是一样的投射到浮动..请检查我更新的帖子也许你可以帮助修复它
标签: c# contrast colormatrix