Prashant Cholachagudda
Prashant Cholachagudda

Reputation: 13092

black and white Image processing in C#

alt text
(source: googlepages.com)

In above image I want to mark Circle's edge with red color something like this

alt text
(source: googlepages.com)

I have no idea how should proceed, Any help/suggestions would be highly appreciated...

Upvotes: 2

Views: 4223

Answers (12)

I think the answer to your question is the answer

http://csharpkodu.blogspot.com.tr/2014/04/grafik-snfna-devam.html

Upvotes: -1

sourcenouveau
sourcenouveau

Reputation: 30504

Morphological filtering would work great as long as you are working with binary images like the one you provided. Dilate the image and then subtract the original.

alt text http://img29.imageshack.us/img29/1420/morphf.png

Here's a MATLAB example:

lImage = zeros(19, 19, 3);
lImage(7:13, 7:13, :) = repmat( ...
    [0 0 1 1 1 0 0; ...
     0 1 1 1 1 1 0; ...
     1 1 1 1 1 1 1; ...
     1 1 1 1 1 1 1; ...
     1 1 1 1 1 1 1; ...
     0 1 1 1 1 1 0; ...
     0 0 1 1 1 0 0;], [1 1 3]);
figure; imshow(lImage);
lOutline = imdilate(lImage, strel('disk', 1)) - lImage;
lOutline(:, :, 2:3) = 0;
figure; imshow(lImage + lOutline);

Upvotes: 3

Samuel Carrijo
Samuel Carrijo

Reputation: 17919

Quick and dirty solution. Run the image pixel by pixel, if the color change, just paint the pixel red.

PS: Notice this may not work for a square, unless you do the same vertically and horizontally

Upvotes: 4

QueueHammer
QueueHammer

Reputation: 10824

Edge detection? Image processing? OpenCV! There are C# wrappers for the lib. Not the "easy" solution but any exp you get with this lib is a good resume builder. If you company is doing image processing they are probably already using it.

Upvotes: 0

Darien Ford
Darien Ford

Reputation: 1049

Ultimately you want to edit the pixels of the image. That question has already been answered here by Marc Gravell.

Then, based on which option you choose, either LockBits or GetPixel/SetPixel, you will need to loop through and look at the per pixel color values. Keep looping until you hit a white pixel.

Once you do, check in all directions around it, if you find a black pixel, then color that white pixel red. This is of course the most simplistic answer, and there are ways to optimize it, but it will work.

For instance, if you wanted to limit the color changing to just the four directly adjacent pixels, you could, rather than also checking the diagonals.

Upvotes: 0

ThibThib
ThibThib

Reputation: 8210

There is several approach for this.

The first one is: - you know that there is a circle, and you juste need to find where is the center and how is the radius. So you can use Hough transformation to find these, and them draw your circle in red. Read this topic or this one

The 2nd is to use edge detection. Here or here (here for more theoritical point of view)

Upvotes: 0

plinth
plinth

Reputation: 49179

You almost assuredly want to use the Canny Edge Detector, which should be able to do this easily. My company's product line includes just such a tool, and this is the output of running it: alt text http://www.plinth.org/_images/image1Output.gif

Upvotes: 2

hugoware
hugoware

Reputation: 36397

Interesting problem - I'm assuming the 'white circle' in your example is actually another image - meaning you aren't drawing the circle yourself?

If so, you might scan through all of the pixels to find a white pixel that has black on at least one side of it (either 4 directions or 8 including corners). If it is a match then swap it to red. If not then ignore it.

I doubt that is the best way to do it, but if it is only black and white, this might get you started.

Upvotes: 0

Bryan Rowe
Bryan Rowe

Reputation: 9303

Never had to do anything like this, but a powerful tool for complex image manipulation is:

http://www.imagemagick.org/script/index.php

Lots of documentation and examples -- and a .NET wrapper if you'd rather not call the executable.

Upvotes: 0

David Hedlund
David Hedlund

Reputation: 129782

i can at least point you in the direction of some pretty neat edge detection filters: http://www.codeproject.com/KB/GDI-plus/edge_detection.aspx

i imagine it should suit you quite well

Upvotes: 0

casperOne
casperOne

Reputation: 74530

What you are looking for is edge detection. You can find a number of resources for the general algorithm on Google:

http://www.google.com/search?q=edge+detection+.net

Upvotes: 0

Anton Gogolev
Anton Gogolev

Reputation: 115691

I guess you need an edge detection algorithm. Try this or this.

Upvotes: 1

Related Questions