简体   繁体   English

C#中的黑白图像处理

[英]black and white Image processing in C#

替代文字
(source: googlepages.com ) (来源: googlepages.com

In above image I want to mark Circle's edge with red color something like this 在上面的图像中,我想用红色标记Circle的边缘

替代文字
(source: googlepages.com ) (来源: googlepages.com

I have no idea how should proceed, Any help/suggestions would be highly appreciated... 我不知道该怎么办,任何帮助/建议都会受到高度赞赏......

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:注意这可能不适用于正方形,除非你在垂直和水平方向上做同样的事情

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

You almost assuredly want to use the Canny Edge Detector , which should be able to do this easily. 您几乎肯定想要使用Canny Edge Detector ,它应该能够轻松完成。 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 我公司的产品线包括这样一个工具,这是运行它的输出: alt text http://www.plinth.org/_images/image1Output.gif

I guess you need an edge detection algorithm. 我想你需要一个边缘检测算法。 Try this or this . 试试这个或者这个

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 http://www.google.com/search?q=edge+detection+.net

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 我想它应该适合你

Never had to do anything like this, but a powerful tool for complex image manipulation is: 从来没有做过这样的事情,但是复杂图像处理的强大工具是:

http://www.imagemagick.org/script/index.php 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包装器。

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). 如果是这样,您可以扫描所有像素以找到在其至少一侧上具有黑色的白色像素(4个方向或8个包括角)。 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. 我怀疑这是最好的方法,但如果它只是黑色和白色,这可能会让你开始。

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. 所以你可以使用Hough变换找到它们,然后用红色绘制你的圆圈。 Read this topic or this one 阅读本主题 主题

The 2nd is to use edge detection. 第二是使用边缘检测。 Here or here ( here for more theoritical point of view) 这里这里这里有更多的理论观点)

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. 然后,根据您选择的选项LockBits或GetPixel / SetPixel,您需要循环查看每像素颜色值。 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. 例如,如果您想将颜色更改为仅限于四个直接相邻的像素,则可以,而不是检查对角线。

Edge detection? 边缘检测? Image processing? 图像处理? OpenCV ! OpenCV There are C# wrappers for the lib. lib有C#包装器。 Not the "easy" solution but any exp you get with this lib is a good resume builder. 不是“简单”的解决方案,但是使用此lib获得的任何exp都是一个很好的简历构建器。 If you company is doing image processing they are probably already using it. 如果你的公司正在进行图像处理,他们可能已经在使用它。

I think the answer to your question is the answer 我认为你的问题的答案就是答案

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM