灰度图像处理 [英] Gray Scale image Processing

查看:80
本文介绍了灰度图像处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨 我想从图案中剪裁图像
该算法的输出是图像像素为1值,图案为0值的位数组,该算法更多用于指纹或人脸检测.
可以帮我吗?
谢谢s

解决方案

您的问题不清楚,但我想我理解您的尝试.好吧,这是两件事之一.我将假设您在图像中只有一个手指印或一张脸.如果您有更多设备,则必须将每个设备分开以正确执行第二个操作.

第一名:
如果要从二进制映射(1和0的输出)中查找原始图像数据,则需要遍历输出数据,只需将其sx,y数据引用到图像即可:

 // 存储它的位置
// 在位图中假设原始图像称为original_image 
// 并在位图中输出名为output_data的图像

位图my_new_image = 位图(原始图像.宽度,原始图像.高度);

 for ( int  y =  0 ; y <  myImage.Height; y ++)
{
    for ( int  x =  0 ; x <  myImage.Width; x ++)
   {
        颜色c = output_data.GetPixel(x,y); // 假设它在图片框中,可能需要根据图片格式进行更改
        如果(output_data.R ==  255 && output_data.G ==  255 )此处的内容取决于图像格式
        {
              my_new_Image.SetPixel(x,y,original_image.GetPixel(x,y););
        }
        myImage.SetPixel(x,y,Color.FromArgb(luma,luma,luma));
   }
} 




第二名:
现在,替代方案是您想要一个手指或脸部位于原始图像内的矩形.同样,您必须遍历结果数据,而在这里要记录数据的左上角位置和数据的右下角位置很容易.

 // 此减速很重要,例如X_min = 0将永远不会保持正确的值最小X位置

 int  X_min = myImage.Width,X_max =  0 ;
 int  Y_min = myImage.Height,Y_max =  0 ;

 for ( int  y =  0 ; y <  myImage.Height; y ++)
{
     for ( int  x =  0 ; x <  myImage.Width; x ++)
    {
        颜色c = output_data.GetPixel(x,y); // 与上述相同的假设
        如果(output_data.R ==  255 && output_data.G ==  255 )
        {
             如果(x> X_max)X_max = x; // 记录最大X位置
             如果(x  if (x> Y_max)Y_max = y; // 记录最大Y位置
             如果(x> Y_min)Y_min = y; // 记录最小Y位置
        }
    }
}
矩形位置= 矩形(X_min,Y_min,X_max,Y_max); // 您可以使用此数据在原始图像上绘制一个矩形. 



由于您提到了人脸检测并且您正在用c#进行复杂的图像处理,因此我建议您转移到 EMGU [ ^ ],这是opencv图像处理库的c#包装器.这将允许对图像处理算法进行更简单的编程,并且用于人脸检测的Haar分类器更加有效,并且输出位置像我在这里提到的第二个过程一样,是一篇很好的文章 ^ ].

我希望这会有所帮助,
干杯
克里斯


hi i want cut the image from pattern
the output of this algorithm is array of bit that image pixel has 1 value and pattern has 0 value,more this algorithm used in fingerPrint or face detection.
Can help me???
thank''s

解决方案

Your question isn''t clear but I think I understand what your attempting to do. Well it''s one of two things. I will assume that you have only one finger print or face within the image. If you have more you will have to separate each one to perform the second operation correctly.

1st:
If you want to find the original image data from a binary map (the output of 1''s and 0''s) you need to loop through your output data and simply reference it''s x,y data to the image:

//somewhere to store it
//Assume orginal image in Bitmap called original_image
//and output image in Bitmap called output_data

Bitmap my_new_image = new Bitmap(original_image.Width,  original_image.Height);

for (int y = 0; y < myImage.Height; y++)
{
   for (int x = 0; x < myImage.Width; x++)
   {
        Color c = output_data.GetPixel(x, y); //Assuming it is in a picturebox this may need to be change depending on image format
        if(output_data.R == 255 && output_data.G == 255 && output_data.B == 255)//Same here depends on image format
        {
              my_new_Image.SetPixel(x, y, original_image.GetPixel(x, y););
        }
        myImage.SetPixel(x, y, Color.FromArgb(luma, luma, luma));
   }
}




2nd:
Now the alternative is you want a rectangle where the finger or face is located within the original image. Again you have to loop through your result data instead here you want to record the top left position of data and the bottom right position of data it''s easily done.

//this deceleration important as if X_min = 0 for example will never hold the correct value for minimum X position

int X_min = myImage.Width, X_max = 0;
int Y_min = myImage.Height, Y_max = 0;

for (int y = 0; y < myImage.Height; y++)
{
    for (int x = 0; x < myImage.Width; x++)
    {
        Color c = output_data.GetPixel(x, y); //Same assumptions made as above
        if(output_data.R == 255 && output_data.G == 255 && output_data.B == 255)
        {
             if(x>X_max) X_max = x; //record max X position
             if(x             if(x>Y_max) Y_max = y; //record max Y position
             if(x>Y_min) Y_min = y; //record min Y position
        }
    }
}
Rectangle location = new Rectangle(X_min, Y_min, X_max, Y_max); //you can use this data to draw a rectangle on your original image.



Since you mention face detection and you are doing complex image processing in c# I would recommend transferring to EMGU [^] which is c# wrapper for opencv image processing library. It will allow simpler programming of image processing algorithms and the Haar Classifiers for face detection are more efficient and output location like the 2nd process I have mentioned here is a good article Multiple face detection and recognition in real time[^].

I hope this helps,
Cheers
Chris


这篇关于灰度图像处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆