C#中的黑白图像处理

时间:2023-02-10 00:13:07

alt text http://parasu516.googlepages.com/Image1.gif

alt text http://parasu516.googlepages.com/Image1.gif

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

在上面的图像中,我想用红色标记Circle的边缘

alt text http://parasu516.googlepages.com/Image.gif

替代文字http://parasu516.googlepages.com/Image.gif

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

我不知道该怎么办,任何帮助/建议都会受到高度赞赏......

12 个解决方案

#1


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

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

Here's a MATLAB example:

这是一个MATLAB示例:

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);

#2


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

PS:注意这可能不适用于正方形,除非你在垂直和水平方向上做同样的事情

#3


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

我想你需要一个边缘检测算法。试试这个或者这个。

#4


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

您几乎肯定想要使用Canny Edge Detector,它应该能够轻松完成。我公司的产品线包括这样一个工具,这是运行它的输出:alt text http://www.plinth.org/_images/image1Output.gif

#5


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

您正在寻找的是边缘检测。您可以在Google上找到适用于常规算法的大量资源:

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

#6


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

我至少可以指向一些漂亮的边缘检测过滤器:http://www.codeproject.com/KB/GDI-plus/edge_detection.aspx

i imagine it should suit you quite well

我想它应该适合你

#7


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.

大量文档和示例 - 如果您不想调用可执行文件,还需要.NET包装器。

#8


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.

如果是这样,您可以扫描所有像素以找到在其至少一侧上具有黑色的白色像素(4个方向或8个包括角)。如果匹配则将其交换为红色。如果没有,那么忽略它。

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

我怀疑这是最好的方法,但如果它只是黑色和白色,这可能会让你开始。

#9


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

第一个是: - 你知道有一个圆圈,你需要找到中心的位置和半径。所以你可以使用Hough变换找到它们,然后用红色绘制你的圆圈。阅读本主题或本主题

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

第二是使用边缘检测。这里或这里(这里有更多的理论观点)

#10


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

最终你想要编辑图像的像素。 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.

然后,根据您选择的选项LockBits或GetPixel / SetPixel,您需要循环查看每像素颜色值。保持循环直到你碰到一个白色像素。

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.

例如,如果您想将颜色更改为仅限于四个直接相邻的像素,则可以,而不是检查对角线。

#11


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.

边缘检测?图像处理? OpenCV的! lib有C#包装器。不是“简单”的解决方案,但是使用此lib获得的任何exp都是一个很好的简历构建器。如果你的公司正在进行图像处理,他们可能已经在使用它。

#12


I think the answer to your question is the answer

我认为你的问题的答案就是答案

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

#1


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

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

Here's a MATLAB example:

这是一个MATLAB示例:

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);

#2


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

PS:注意这可能不适用于正方形,除非你在垂直和水平方向上做同样的事情

#3


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

我想你需要一个边缘检测算法。试试这个或者这个。

#4


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

您几乎肯定想要使用Canny Edge Detector,它应该能够轻松完成。我公司的产品线包括这样一个工具,这是运行它的输出:alt text http://www.plinth.org/_images/image1Output.gif

#5


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

您正在寻找的是边缘检测。您可以在Google上找到适用于常规算法的大量资源:

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

#6


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

我至少可以指向一些漂亮的边缘检测过滤器:http://www.codeproject.com/KB/GDI-plus/edge_detection.aspx

i imagine it should suit you quite well

我想它应该适合你

#7


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.

大量文档和示例 - 如果您不想调用可执行文件,还需要.NET包装器。

#8


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.

如果是这样,您可以扫描所有像素以找到在其至少一侧上具有黑色的白色像素(4个方向或8个包括角)。如果匹配则将其交换为红色。如果没有,那么忽略它。

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

我怀疑这是最好的方法,但如果它只是黑色和白色,这可能会让你开始。

#9


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

第一个是: - 你知道有一个圆圈,你需要找到中心的位置和半径。所以你可以使用Hough变换找到它们,然后用红色绘制你的圆圈。阅读本主题或本主题

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

第二是使用边缘检测。这里或这里(这里有更多的理论观点)

#10


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

最终你想要编辑图像的像素。 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.

然后,根据您选择的选项LockBits或GetPixel / SetPixel,您需要循环查看每像素颜色值。保持循环直到你碰到一个白色像素。

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.

例如,如果您想将颜色更改为仅限于四个直接相邻的像素,则可以,而不是检查对角线。

#11


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.

边缘检测?图像处理? OpenCV的! lib有C#包装器。不是“简单”的解决方案,但是使用此lib获得的任何exp都是一个很好的简历构建器。如果你的公司正在进行图像处理,他们可能已经在使用它。

#12


I think the answer to your question is the answer

我认为你的问题的答案就是答案

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