그림에서 관심 영역을 계산하는 작은 도구를 만들려고합니다.C에서 대비를 조정 한 후 그래픽 수정
더 나은 결과를 얻으려면 이미지의 대비를 조정해야합니다. Colormatrix-System을 사용하여이 작업을 수행하려고하면 조정 된 이미지 대신 원본 이미지의 결과가 나타납니다.
다음은 나의 코드입니다.
{
count = 0;
Bitmap nB = new Bitmap(newBitmap.Width, newBitmap.Height);
int lastCol = 1;
//int y =250;
int countStart = 1;
int countEnd = 1;
Here is the code of the routine:
for (int y = 1; y < newBitmap.Height - 1; y++)
{
for (int x = 1; x < newBitmap.Width - 1; x++)
{
Color pixel = newBitmap.GetPixel(x, y);
int colVal = (pixel.R + pixel.G + pixel.B);
if (lastCol == 1) lastCol = (pixel.R + pixel.G + pixel.B);
int diff;
diff = colVal - lastCol;
//if (colVal > lastCol) { diff = colVal - lastCol; } else { diff = lastCol - colVal; }
if (diff > 50)
{
roiCount = true;
countEnd = x;
adjusted.SetPixel(x, y, Color.Red);
lastCol = colVal;
//count++;
}
else if (diff < -50)
{
//roiCount = true;
countStart = x;
adjusted.SetPixel(x, y, Color.Blue);
lastCol = colVal;
}
if (roiCount)
{
for (int i = countStart; i < countEnd; i++)
{
adjusted.SetPixel(i, y, Color.Green);
}
int roiCenter = (countStart + countEnd)/2;
//int roiYTest = y + 1;
Color roiCenterPixel = newBitmap.GetPixel(roiCenter, y);
int colRoiCenterPixel = roiCenterPixel.R + roiCenterPixel.G + roiCenterPixel.B;
Color PixelRoi = newBitmap.GetPixel(roiCenter, y + 1);
int colRoi = (PixelRoi.R + PixelRoi.G + PixelRoi.B);
int diffRoi = colRoiCenterPixel - colRoi;
if (diffRoi < -50 || diffRoi > 50)
{
count++;
}
roiCount = false;
//count++;
}
}
}
label17.Text = Convert.ToString(count); pictureBox1.Image = nB;
: 그 후 나는 다음과 같은 방법으로 대비를 조정
Img = Image.FromFile(openFileDialog1.FileName);
newBitmap = new Bitmap(openFileDialog1.FileName);
: 우선 나는 다음과 같은 방법으로 이미지를로드 ROI를 계산하는 코드는 여기
{
domainContrast.Text = trackBar2.Value.ToString();
contrast = 0.04f * trackBar2.Value;
Bitmap bm = new Bitmap(newBitmap.Width, newBitmap.Height);
Graphics g = Graphics.FromImage(bm);
ImageAttributes ia = new ImageAttributes();
ColorMatrix cm = new ColorMatrix(new float[][] {
new float[] {contrast, 0f, 0f, 0f, 0f},
new float[] {0f, contrast, 0f, 0f, 0f},
new float[] {0f, 0f, contrast, 0f, 0f},
new float[] {0f, 0f, 0f, 1f , 0f},
new float[] {0.001f, 0.001f, 0.001f, 0f, 1f}
});
ia.SetColorMatrix(cm);
g.DrawImage(newBitmap, new Rectangle(0, 0, newBitmap.Width, newBitmap.Height), 0, 0, newBitmap.Width, newBitmap.Height, GraphicsUnit.Pixel, ia);
g.Dispose();
ia.Dispose();
pictureBox1.Image = bm;
}
그리고이다
추가적으로, 그것은 rois의 색깔을 녹색으로 바꾼다. 카운팅 루틴은 제대로 작동하지만, 내가 말했듯이 원래의 이미지를 사용합니다. 조정 된 이미지를 사용하려면 계산 루틴에 "알리는"방법은 무엇입니까? 원본 이미지에 수정 사항을 쓰려면 어떻게해야합니까?
도움 주셔서 감사합니다.
티모
시도해 보았습니다. 나는 루틴의 내부에 많은 "스파게티 코드"를 썼다. 나는 그것을 언급하는 것이 약간 정신이 빠르다 고 생각했다. – csharper1981
내 질문에 코드 조각을 추가했습니다. – csharper1981
그건 그렇고, * 내가 그것을 시도하고 StackOverflow에서 * upvote 및/또는 답변을 받아 들일 수있다 ;-) –