How can i invert colors in an character image?
6 views (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
elyo
on 23 Aug 2011
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
More Answers (1)
farhan rana
on 10 Oct 2011
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 :(
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!