用彩色矩阵对比 [英] contrast with color matrix
问题描述
您好我想实现我的应用程序如这个环节的对比过滤器或这种对比但随着彩色矩阵和跟踪栏值< BR>
我已经找到彩色矩阵它
浮法C = mytrackbar.value * 0.01F // maxTrackbarValue = 100,minTrackbarValue = -100
浮动T = 0.01F;
cmPicture =新嘉洛斯(新浮法[] [] {
新的浮动[] {C,0,0,0,0},
新的浮动[] {0,C 0 ,0,0},
新的浮动[] {0,0,C,0,0},
新的浮动[] {0,0,0,1,0},
新的浮动[] {T,T,T,0,1}
});
但结果是非常不同的。我试图改变在〜 0.01F C〜并在〜牛逼〜值 0.01F,但只给出了结果如亮度
(例如:C = mytrackbar。值* 0.04f)
我不知道〜C〜&安培; 〜〜ŧ价值多少最大和最小范围内,我应该用于创建对比度
更新@Nico
私人无效myTrackBar_ValueChanged(对象发件人,EventArgs五){
imageHandle = imageHandleTemp.Bitmap;
myNumericUpDown.Text = myTrackBar.Value.ToString();
浮点值= myTrackBar.Value * 0.01F;
位图bmpInverted =新位图(imageHandle.Width,imageHandle.Height);
ImageAttributes IA =新ImageAttributes();
嘉洛斯cmPicture =新嘉洛斯();
浮点C =价值;
浮动T = 0.01F;
cmPicture =新嘉洛斯(新浮法[] [] {
新的浮动[] {C,0,0,0,0},
新的浮动[] {0,C 0 ,0,0},
新的浮动[] {0,0,C,0,0},
新的浮动[] {0,0,0,1,0},
新的浮动[] {T,T,T,0,1}
});
ia.SetColorMatrix(cmPicture);
图形G = Graphics.FromImage(bmpInverted);
g.DrawImage(imageHandle,新矩形(0,0,imageHandle.Width,imageHandle.Height),0,0,imageHandle.Width,imageHandle.Height,GraphicsUnit.Pixel,IA);
g.Dispose();
形象和LT; BGR,字节> MYIMAGE =新的图像< BGR,字节>(bmpInverted);
imageBoxCamera.Image = MYIMAGE;
}
t值为必须< STRONG>在新的对比度值C衍生。所以改变这样的任务:
浮动T =(1.0F - C)/ 2.0F;
根据这个漂亮的链接嘉洛斯指南矩阵代码的其余部分似乎是确定。
请注意:我错了C的范围内! c的值是的不是一个绝对值,但它是在系数应该应用!所以为双击对比度应该 2F
注2:你的代码是不是源不太清楚和目标;因为你正在改变与所述的TrackBar飞对比度它应当清楚的是,直到应用的变化,
-
的中间结果必须总是从同一原始位图来计算。
-
此外,该跟踪条应该是这样intialized,它与1
- 最后,为了降低对比度值应转化至0℃; C< 1
A值开始
尼科的建议 C = 1 +值;
将很好地一起工作您的原始的范围为-100至+100为0的初值和你的因素0.01F。
Hi I want to implement contrast filter in my application like this link or this contrast but with color matrix and track bar for value
I already found color matrix for it
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}
});
but the result is very different. I try to change 0.01f in ~c~ and 0.01f in ~t~ value but it only gives result like brightness (ex : c = mytrackbar.value * 0.04f )
I wonder what ~c~ & ~t~ value and how many max and min range i should used for created contrast
Update @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;
}
The t value must be derived from the new contrast value c. so change its assignment like this:
float t = (1.0f - c) / 2.0f;
According to this nice link to the ColorMatrix Guide the rest of the matrix code seems to be OK.
Note: I was wrong about the range of c!! The value of c is not an absolute value but it is the factor that should be applied! So to double the contrast it should be 2f.
Note 2: Your code is not quite clear about source and target; and since you are changing contrast on the fly with the trackbar it should be clear that until the change is applied,
The intermediate results must always be calculated from the same original bitmap.
Also, that the trackbar should be so intialized that it starts with a value of 1.
- And finally, in order to reduce contrast values should translate to 0 < c < 1.
Nico's suggestion c = 1+ value;
would work nicely with your original range -100 to +100 with an intial value of 0 and your factor 0.01f.
这篇关于用彩色矩阵对比的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!