How can i invert colors in an character image?

I started working on handwritten English character recognition using neural network. In my scanned character images, characters are written in black color with a white background. Is there any function in MATLAB which can convert the character image's background color into black and the printed character into white color?
Actually in the process of skeletonization (thinning) of the character image, i used a function "bwmorph", which works well if the character is written with white color on a black background. The code i used was:
Img1=bwmorph(Img,'skel',Inf);
It works correctly if Img is the character image with white character on black background but doesn't work when i take Img as a black ink character with white background.
Is there any other alternative of "bwmorph"? or any other code used for thinning the character image..
Thanks... -Amit

 Accepted Answer

I suppose you already converted the grayscale image to binary using im2bw(). Then, all you have to do is:
Img1 = bwmorph(1-Img,'skel',Inf);
The expression 1-Img converts all ones to zeros and vice versa.
Good luck!
Elyo Ravuna

1 Comment

Thanks a lot for my help...
Is there any other efficient code for thinning the character image?
Thanks...

Sign in to comment.

More Answers (1)

there was an even simpler way to do this but i dont remember it correctly. all it took was subtracting 1 from the image or something. forgive me for not remembering correctly :(

Asked:

on 23 Aug 2011

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!