×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Registered User
    Join Date
    Oct 2006
    Location
    germany
    Posts
    14

    Image processing - Sobel filter problem (edge detection)

    Hi everyone,

    I'm trying to perform edge detection on a bitmap I get from the camera viewfinder, using a simple sobel operator. It's quite a straight forward task, but somehow the result doesn't look like expected (something like this for the x/y gradients: http://www.dca.fee.unicamp.br/dipcou...-sobel-x-y.gif )

    This is my code (both bitmaps are EGray256):
    Code:
    	    
    	iGrayBitmap->LockHeap(ETrue);
    	TInt8* gImg = (TInt8*)iGrayBitmap->DataAddress();
    	TInt8* proImg = (TInt8*)iProcessedBitmap->DataAddress();
    	iGrayBitmap->UnlockHeap(ETrue);
    
    	TInt x=0, y=0, i=0, dx=0, dy=0;		
    
    	for(i=0; i<w*h; i++) 
    		{
    		// if we're at the first column - first pixel of a row:
    		// increment rows x and reset columns y
    		if (i==(y+1)*w) { y++; x=0; }
                    // else increment columns
    		else { x++; }
    		
    		// if we're not in the first column or the first/last row (image boundaries)
    		// apply Sobel filter
    		if(x!=0 && x!=w-2 && y!=0 && y!=h-2 )
    			{
    			dx = gImg[i-w-1] + gImg[i-w+1] + gImg[i-w]*2 - gImg[i+w-1] - gImg[i+w+1] - 2*gImg[i+w];
    						
    			dy = gImg[i-w-1] + gImg[i+w-1] + gImg[i-1]*2 - gImg[i-w+1] - gImg[i-w+1] - 2*gImg[i+1];
    			
                            proImg[i] = dx;
    
    			}
    		else
    			{
    			proImg[i] = 255;
    			}
    		
    		}
    As you can see here, the edges are detected, but where does all the white noise come from? Shouldn't it be just plain gray? (the test image is a white triangle on a light gray background, the screenshot is from the horizontal gradient)
    http://tinypic.com/r/dpg1gh/3
    Original image:
    http://tinypic.com/r/11r7h37/3

    Does anybody see what might be the problem?

    Thanks
    Last edited by sbail; 2009-07-25 at 16:39.

  2. #2
    Regular Contributor
    Join Date
    Apr 2004
    Posts
    96

    Re: Image processing - Sobel filter problem (edge detection)

    You should show original image if you want meaningful answer. Anyway dy seems wrong.

  3. #3
    Registered User
    Join Date
    Oct 2006
    Location
    germany
    Posts
    14

    Re: Image processing - Sobel filter problem (edge detection)

    Thanks for your reply, I've uploaded the original image:
    Original image:
    http://tinypic.com/r/11r7h37/3


    As an addition, this is a screenshot from a plain black image (camera lid is shut):
    http://tinypic.com/r/bfgk0w/3

  4. #4
    Regular Contributor
    Join Date
    Apr 2004
    Posts
    96

    Re: Image processing - Sobel filter problem (edge detection)

    Yep, you should get something like first image. Sobel doesn't do smoothing, you should get a lot of noise. You can pass through smoothing filter before edge detection filter. And don't forget fix error in dy - your code is not a sobel now.

  5. #5
    Registered User
    Join Date
    Oct 2006
    Location
    germany
    Posts
    14

    Re: Image processing - Sobel filter problem (edge detection)

    Okay, I've fixed the error in dy, well spotted, thanks

    So you say the only reason why the filter produces so much noise is because there is no smoothing, but the sobel itself is okay?

  6. #6
    Registered User
    Join Date
    Oct 2006
    Location
    germany
    Posts
    14

    Re: Image processing - Sobel filter problem (edge detection)

    Okay, problem solved!
    dx caused some problems when trying trying to convert it into a TUint8 (I expected it to work without explicitly specifying anything - but it didn't)
    I use TUint8 (Abs(dx)) now and (TUint8) (Abs(dx) + Abs(dy)) for the gradient magnitude. Looks normal now, as expected.

    Thanks for checking the code.

Similar Threads

  1. Problem regarding creating ROM image
    By eternity007 in forum Symbian Tools & SDKs
    Replies: 2
    Last Post: 2009-05-21, 09:37
  2. image uploading problem
    By vkrnt18 in forum General Development Questions
    Replies: 3
    Last Post: 2007-06-22, 14:01
  3. image processing problem
    By alexboy in forum Mobile Java Media (Graphics & Sounds)
    Replies: 3
    Last Post: 2006-11-08, 05:36
  4. how to cut some part of Image
    By mshouab in forum Mobile Java Media (Graphics & Sounds)
    Replies: 2
    Last Post: 2006-08-04, 09:05
  5. Replies: 1
    Last Post: 2003-04-19, 22:28

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×