谁能告诉我代码行的含义或算法的名称? [英] Can anyone tell me the meaning of the code lines or the algorithm's name?

查看:72
本文介绍了谁能告诉我代码行的含义或算法的名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!



我是c#的新生。我正在制作项目Fintgerprint识别,我无法理解这种方法,它获得了将普通图像转换为二值图像的阈值。谁能告诉我算法或算法的名字?



非常感谢你!



   #region Threshold caculate 

public int GetThreshold()
{
int threshold = 0 ;
double tempF = 0 ;
for int g = 0 ; g< = 255 ; g ++)
if (GetF(g)> tempF)
{
tempF = GetF(g);
threshold = g;
}
返回阈值;

}
// 帮助函数
< span class =code-keyword> private
int GetT( int g)
{
int t = 0 ;
int x,y;
for (x = 0 ; x< width; x ++)
(= = 0 ; y< height; y ++)
if (image [x,y] < = g)t ++;

return t;
}
私有 double GetM( int g)
{
int x,y;
int temp = 0 ;
for (x = 0 ; x< width; x ++)
(= = 0 ; y< height; y ++)
if (image [x,y] < = g)temp + = image [x,y];
double m = Convert.ToDouble(temp)/Convert.ToDouble(GetT(g));
返回 m;
}
私有 double GetF( int g)
{
return Convert.ToDouble(GetT(g))*(GetM(g)-GetM( 255 ))*(GetM(g)-GetM( 255 ))/ Convert.ToDouble((width *高)-GetT(克));
}
#endregion

解决方案

我建​​议你回到你发现代码的地方,并在那里问...在逐行解释代码不是一个快速的任务!



您是否知道逐行解释代码的工作量是多少?

每一行都需要一段解释!例如:

 int next = r.Next(); 



创建一个名为next的新变量,它可以包含一个整数值。从先前声明的Random实例r,调用Next方法获取一个新的随机数,并将其分配给next变量。



可以你想象我们需要多长时间才能解释一个像你的例子一样的非常短的代码片段,一行一行?



不会发生这种情况。如果您有特定问题,请询问有关它的问题。但首先考虑一下 - 你想坐下45分钟然后输入逐行描述没有充分理由吗?


你可能已经理解现在没有人特别感兴趣的是检查你在某个地方找到的代码,并花时间为你分析它。

这样做需要在图像上实际运行代码并使用调试器来了解发生了什么。



你最好不要试图找到算法,理解它然后再制作代码。



使用此搜索短语图像处理中的阈值计算将为您提供充足的起点。



例如阈值处理(图像处理) [ ^ ]



因此,请丢弃该代码并重新开始。

此剪辑集只是计算图像的阈值

输入图像是256级灰度,目标是使用阈值将其转换为黑白。



引用:

我是c#的新生。我正在制作项目Fintgerprint recognition

这个copde与指纹识别无关,它只与图像处理有关,以便于以后提取有用的信息。



关于剪辑集我可以说的是,它是以非常天真的方式编写的,效率非常低。快速查看让我估计如果优化速度提高500-1000倍。



对于算法,请查看https://homes.di.unimi.it/ferrari/ElabImm2011_12/EI2011_12_16_segmentation_double.pdf [ ^ ]


Hi!

I'm new student in c#. I am making project "Fintgerprint recognition", i cann't understand this method, it get the threshold to convert normal image to binary image. Can anyone tell me the algorithm or the algorithm's name?

Thank you very much!

#region Threshold caculate

		public int GetThreshold()
		{
			int threshold = 0;
			double tempF = 0;
			for(int g=0;g<=255;g++)
				if(GetF(g)>tempF)
				{
					tempF = GetF(g);
					threshold = g;
				}
			return threshold;
			
		}
		//helper functions
		private int GetT(int g)
		{
			int t = 0;
			int x,y;
			for(x=0;x<width;x++)
				for(y=0;y<height;y++)
					if(image[x,y]<=g) t++;

			return t;
		}
		private double GetM(int g)
		{
			int x,y;
			int temp = 0;
			for(x=0;x<width;x++)
				for(y=0;y<height;y++)
					if(image[x,y]<=g) temp += image[x,y];
			double m = Convert.ToDouble(temp)/Convert.ToDouble(GetT(g));
			return m;
		}
		private double GetF(int g)
		{			
			return Convert.ToDouble(GetT(g))*(GetM(g)-GetM(255))*(GetM(g)-GetM(255))/Convert.ToDouble((width*height)-GetT(g));
		}
		#endregion	

解决方案

I'd suggest that you go back to wherever you found that code, and ask there...explaining code on a line by line basis is not a quick task!

Do you have any idea how much work explaining code line by line is?
Every single line needs a paragraph of explanation! For example:

int next = r.Next();


Create a new variable called "next" which can hold a integer value. From the previously declared Random instance "r", call the "Next" method to get a new random number, and assign it to the "next" variable.

Can you imagine how long it would take us to explain even a very short code fragment like your example, line by line?

No. It is not going to happen. If you have a specific problem, then ask a question about it. But think first - would you want to sit down for 45 minutes and type up a line-by-line description for no good reason?


As you might have understood by now there is no one particularly interested in reviewing the code you found "somewhere" and put in the time to analyze it for you.
Doing that require to actually run the code on an image and using the debugger to understand what is happening.

You are better off trying to find an algorithm, understand it and then make the code.

Using this search phrase "threshold calculation in image processing" will give you plenty of starting points.

For example Thresholding (image processing)[^]

So throw away that code and start over.


This snipset is simply computing the threshold of an image.
the input image is 256 shades of grey and the goal is to convert it to black and white using the threshold.

Quote:

I'm new student in c#. I am making project "Fintgerprint recognition"

This copde is not related to "fingerprint recognition", it is only related to image treatment in order to ease the later extraction of useful informations.

All I can say about the snipset, is that it is written in a very naive manner and is highly inefficient. A quick look let me estimate a speed improvement of 500-1000 times faster if optimized.

For the algorithm, have a look at https://homes.di.unimi.it/ferrari/ElabImm2011_12/EI2011_12_16_segmentation_double.pdf[^]


这篇关于谁能告诉我代码行的含义或算法的名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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