LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-13-2012, 02:26 AM   #121
jayshri
Member
 
Registered: Feb 2012
Posts: 71

Rep: Reputation: Disabled

hi firstfire,
thank u... the 1st thresholding is running nicely then the 2nd thresholding..
the objects are clear than before..
but
Quote:
is it possible to make the background either totally white or totaly black..
i mean reverse the colour of the object???
Quote:
if the object is of black colour then the back ground is of white colour fully
.
something like this..
Quote:
the method our professor suggested is that an object have 4 coordinates(x+1,x-1,y+1,y-1)..
so the thresolding algorithm will check the intensity of the neighbour of the object and will compare the intensity.. if the intensity of background is like 10% or 20% less then that of intensity of object then it will b supressd
so with 1st thresholding is this algorithm is possible???
this thresholding also known as "INTELLIGENT THRESHOLDING".
thanks and regards..

Last edited by jayshri; 04-13-2012 at 06:33 AM.
 
Old 04-25-2012, 04:18 AM   #122
jayshri
Member
 
Registered: Feb 2012
Posts: 71

Rep: Reputation: Disabled
Quote:
Originally Posted by firstfire View Post
Hi.

I implemented an improved Hough algorithm for finding circles described here. It uses edge orientation information and is much faster than previous straightforward implementation. The search for maxima in the 3-dimensional accumulator array is not very simple. I implemented two types of search -- ordinary thresholding and recursive (though without direct use of recursion) search. The latter should reduce multiple matches. Neither is perfect.

Code:
typedef unsigned int stack_t;
#define sign(x) (x>0?1:-1)
void hough_circ_grad(pixel_t *orig, pixel_t *edge, BITMAPINFOHEADER *ih)
{
	int T;
	unsigned int nx = ih->width, ny = ih->height,
	    X, Y, R,	// coordinates in Hough space
	    i, j, k, max_votes = 0;
	unsigned int	mx = nx / 4,	// Hough space discretization
	    		my = ny / 4,
			mr = 40,
			rmax = 20;	// maximum radius of circles to be found, px.

	int Gx, Gy;	// Gradients
	float slope;
	float	hx = mx / (float)nx,
	    	hy = my / (float)ny,
	    	hr = mr / (float)rmax,
		dx, dy, r;
	unsigned int Ntotal = mx * my * mr, Nxy = mx * my;
	unsigned short *out = calloc(Ntotal, sizeof(unsigned short));
	printf("circular Hough space size %ux%ux%u = %u\n", mx, my, mr, Ntotal);
	if(!out){
		perror("circular_hough_transform()");
		exit(1);
	}
	puts("Hough: init.");
	for(j=1; j<ny-1; j++)
		for(i=1; i<nx-1; i++) {
			if(edge[i+nx*j] < 100) continue;
			Gx = orig[i+1 + nx*j] - orig[i-1+nx*j];
			Gy = orig[i + nx*(j+1)] - orig[i+nx*(j-1)];
			slope = tan( atan2(Gy, Gx) - M_PI/2. );
			for(R=0; R<mr; R++) {
				r = R/(float)hr;
				if(fabs(slope) < 1e-12)
					dx = 0;
				else
					dx =  -sign(Gx) * r / sqrt(1 + 1/slope/slope);
				dy = -sign(Gy) * r / sqrt(1 + slope*slope);
				X = (int)(i + dx) * hx;
				Y = (int)(j + dy) * hy;
				k = X + mx * Y + Nxy * R;
				if(out[k] < USHRT_MAX && k<Ntotal)
				{
					out[k]++;
					if(out[k]>max_votes) max_votes = out[k];
				}
			}
		}
	puts("Hough: accumulation done.");

	T = max_votes*0.5;	// search threshold
	printf("T=%d\n", T);

	unsigned int counter = 0;

	for(i=0; i<Ntotal; i++) if(out[i] < T) counter++;
	printf("zeros=%d of %d: %g\%\n", counter, Ntotal, counter/(float)Ntotal*100);

	int u,v,w, test,
	    sr = 1;	// recursive search radius

	counter = 0;

// #if 1 -- recursive maxima search; should reduce multiple matches for simgle circle.
// #if 0 -- thresholding.
#if 1
	unsigned int smaxsize = 1000,  ssize, k2, maxv, maxk, len;
	stack_t *stack = malloc(sizeof(stack_t)*smaxsize);
	stack_t se;

	for(Y=1; Y<my-1; Y++)
		for(X=1; X<mx-1; X++)
			for(R=3; R<mr-1; R++) {
				k = X + mx * Y + Nxy * R;
				if( out[k] < T ) continue;

				len = 0;
				maxv  = 0;
				ssize = 1;
				stack[0] = k;

				do {
					len++;
					ssize--;
					se = stack[ssize];
					if( out[se] > maxv ) {
						maxv = out[se];
						maxk = se;
					}
					out[se] = 0;	// we were here

					// scan all neighbours
					for(u=-sr;u<=sr;u++)
					for(v=-sr;v<=sr;v++)
					for(w=-sr;w<=sr;w++)
					{
						if(u==0 && v==0 && w==0) continue;
						k2 = se + u+v*mx+w*Nxy;
						if( k2 < Ntotal && out[k2] >= T ) {
							stack[ssize] = k2;
							ssize++;
							if(ssize >= smaxsize){
							  puts("NOTE: Incrementing stack size");
							  smaxsize += 1000;
							  stack = realloc(stack, sizeof(stack_t)*smaxsize);
							}
						}
					}
				} while(ssize > 0);

				//if( len < 3 ) continue;
				R = maxk / (float)Nxy;
				Y = (maxk % Nxy) / (float) mx;
				X = (maxk % Nxy) % mx;// maxk - mx*Y - Nxy*R;
				i = (int)(X/(float)hx);
				j = (int)(Y/(float)hy);
				r = (int)(R/(float)hr);
				printf("%d:\tx=%d\ty=%d\tr=%d (R=%d)\tvotes=%u, k=%d, m=%d\n",
						counter++, X, Y, (int)r, R, maxv, maxk, len);
				cross(edge, ih, i, j, r);

			}
	printf("max stack size = %d\n", smaxsize);
	free(stack);

#else
	for(Y=1; Y<my-1; Y++)
		for(X=1; X<mx-1; X++)
			for(R=5; R<mr-1; R++) {
				k = X + mx * Y + Nxy * R;
				if( out[k] < T /*T*(R+1)*/) continue;
				test = 0;
				
				for(u=-1;u<2;u++)
				for(v=-1;v<2;v++)
				for(w=-1;w<2;w++)
					if( !(u==0 && v==0 && w==0) )
						test += (out[k + u+v*mx+w*Nxy] > out[k]);
						
				if( test == 0 );
				{
					i = (int)(X/(float)hx);
					j = (int)(Y/(float)hy);
					r = (int)(R/(float)hr);
					printf("%d:\tx=%d\ty=%d\tr=%d (R=%d)\tvotes=%u\n",
							counter++, i, j, (int)r, R, out[X + mx * Y + Nxy * R]);
					cross(edge, ih, i, j, r);
				}
			}
#endif
	puts("Hough: search done.");
	printf("Hough: max number of votes %d\n", max_votes);
	free(out);
}
Adjustable parameters are in bold font.

Call this code as follows:
Code:
hough_circ_grad(bitmap_data, temp_image, &ih);
where `temp_image' is the result of Canny edge detection.

For tests I used the picture you provided. Here is the result
Attachment 9297

.
hi firstfire,
you have given me the code for circular hough transform which is being performed after canny edge.. is it possible to do CHT without canny so that the circle is ploted directly on the object can be easily visible on the object??? because after canny all due to all the edges in the picture the circle is not that clear..
regards

Last edited by jayshri; 04-25-2012 at 04:35 AM.
 
Old 04-25-2012, 04:37 AM   #123
jayshri
Member
 
Registered: Feb 2012
Posts: 71

Rep: Reputation: Disabled
the circles should be on original image.. like the attachment i have given below..
thank u
Attached Thumbnails
Click image for larger version

Name:	tem2.gif
Views:	28
Size:	23.9 KB
ID:	9537  
 
Old 01-27-2021, 03:01 PM   #124
digger_404
LQ Newbie
 
Registered: Jan 2021
Posts: 1

Rep: Reputation: Disabled
Found the answer!!!

I didn't read every comment in here, and I don't know if my comment will ever help someone, but here it is:

Working with color images is the same as gray scale ones, the trick is that you need to work each color channel separately, meaning you'll only compare the blues with the blues, the reds with reds and greens with greens. After you get the result for each channel (i.e. 3 values), you'll just save them in the pixel location you are working.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Applying median filter to a picture ... tomazN Programming 7 04-03-2006 05:15 AM
Minolta MC 2300dl + foo2zjs driver = color images printed in black? J_Szucs Linux - Hardware 1 02-06-2006 02:30 AM
What are the color code ? cigarstub Linux - Networking 5 10-22-2005 10:51 AM
how to draw color images with xlib? BBB Programming 19 07-15-2005 02:04 PM
filter the code Xiangbuilder Programming 7 10-23-2003 07:28 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:07 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration