Click here to Skip to main content
12,947,539 members (56,207 online)
Click here to Skip to main content
Add your own
alternative version


23 bookmarked
Posted 14 Dec 2004

Image Segmentation using Gradient method

, 14 Dec 2004
Rate this:
Please Sign up or sign in to vote.
Automatic Detection of stains in a camera lens using Image Segmentation

Sample Image - dimimg.jpg


This is a pure image processing technique to detect the dims or stains, whatever you call, automatically. It is a type of edge detection method called Gradient Method. It is a type of image segmentation where in which, first applying the Gaussian Lowpass Filter to the image will give you a smoothed image. After that convolving the image with two masks called horizontal and vertical masks, which gives the horizontal and vertical gradient values of the image. To the find the magnitude of the gradient values we have to square the horizontal and vertical values and finding the square root of the combined values. This gives the gradient values of the image. The highest gradient value in the image falls on the edge of the dim or the stain. There we can put an arrow to identify the dim. This technique is purely in spatial domain of the image.

This code hassome bugs. Those are not very serious to effect the actual concept of the code. The bugs are as follows:

  1. 1. The image background is CYAN in color. Actually if you observe the 6 values after 94th byte using any editer like ULTRAEDIT etc.., you can find 0x0D, 0x0A, 0x0D, 0x0A, 0x0D, 0x0A. If you could remove those three 0x0Ds, you can find the image in a pure 8bit gray scale image. This bug is may be due to the typecasting problems with unsigned char.
  2. It cannot dectect more than one dim in the image.
  3. As the thresholding is not done, this algorithm will also place the arrows in an image with out a dim. I commented the thresholding part of the code which you can see at line no. 255. The thresholding value will be approximatley above 1.000. This part is left to the users.

I am trying to overcome the above mentioned bugs in my second version of the program.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Ananth Nag Sastry Ganti
Software Developer
United States United States
I am Ananth Nag Sastry Ganti, working as a software engineer at IBM T.J Watson Research Center, NY. I am working on Image processing and Video suviellence projects. My areas of interests include DSP, Image Processing.

Any advices or suggestions on my articles are always welcome.

You may also be interested in...


Comments and Discussions

Generalcode for image segmentation Pin
Member 77323887-Mar-11 1:31
memberMember 77323887-Mar-11 1:31 
Generalcode 4 image segmentation Pin
nikunjkumar4-Oct-10 8:12
membernikunjkumar4-Oct-10 8:12 
GeneralRe: code 4 image segmentation Pin
Member 77323887-Mar-11 22:34
memberMember 77323887-Mar-11 22:34 
Generalhelp me about color image segmentation Pin
hieulinhanh19-Jul-09 21:14
memberhieulinhanh19-Jul-09 21:14 
GeneralImage Segmentation Pin
Krishna Tagore7-Apr-09 20:11
memberKrishna Tagore7-Apr-09 20:11 
GeneralHelp me in Image processing Pin
hieuvv20-Mar-07 18:02
memberhieuvv20-Mar-07 18:02 
GeneralImage Processing in VC++ 6.0 Pin
karthik_ravikanti4-Aug-06 8:22
memberkarthik_ravikanti4-Aug-06 8:22 
Generalmissing picture Pin
Georgi Petrov23-Feb-05 10:08
memberGeorgi Petrov23-Feb-05 10:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170518.1 | Last Updated 14 Dec 2004
Article Copyright 2004 by Ananth Nag Sastry Ganti
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid