Click here to Skip to main content
15,880,469 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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!

C#
#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	
Posted
Updated 2-Nov-15 14:23pm
v2
Comments
E.F. Nijboer 2-Nov-15 3:53am    
Well this is a nice example why functions should have meaningful names!

Maybe you can figure it out by looking up some methods for finding image threshold.
https://en.wikipedia.org/wiki/Thresholding_%28image_processing%29
Member 12106084 2-Nov-15 5:45am    
Thanks for your help!
BillWoodruff 2-Nov-15 8:41am    
The crystal balls we have here unfortunately do not show us algorithms when we look deeply into code.

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?
 
Share this answer
 
Comments
Member 12106084 2-Nov-15 5:44am    
@OriginalGriff:
I found it in a c# project, and i don't have any infomation about its origin. I just want people to explain the algorithm in the code. Line by line is not my mean.
Thanks for your solution!
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.
 
Share this answer
 
Comments
Member 12106084 3-Nov-15 0:30am    
I'm just started so i was a bit confused.
Thanks for your help!
George Jonsson 3-Nov-15 1:51am    
We all are from time to time.
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[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900