使用阈值分割图像的一部分
我试图隔离并分割黄色车身以改变它的颜色。为了做到这一点,我需要将身体与图像分开识别。并继续用剩余的白色像素进行演讲。我使用 C#,这里的计划
Color d;
Color newColor = Color.YellowGreen;
for(inti =0;i<carimage.Width;i++){
for(intj =0;j<carimage.Height;j++){
d = carimage.GetPixel(i, j);
if(d.R == 255 && d.G==255 && d.B == 255)
image.SetPixel(i, j, newColor );
}
}
简单阈值处理将丢弃车身未正确分离的第二张图像。我尝试了 Aforge.net 填充孔图像过滤器,但阈值图像没有发生重大变化。我尝试使用滤色器,但由于主体的颜色变化,我没有返回正确的输出。任何人都可以为此提出建议和解决方案吗?
原始图像
阈值图像
Im trying to isolate and segment the yellow car body to change the color of it. in order to do that i need to separately identify the body from the image. And continue oration with the remaining white pixels. And im using C#, here the plan
Color d;
Color newColor = Color.YellowGreen;
for(inti =0;i<carimage.Width;i++){
for(intj =0;j<carimage.Height;j++){
d = carimage.GetPixel(i, j);
if(d.R == 255 && d.G==255 && d.B == 255)
image.SetPixel(i, j, newColor );
}
}
simple thresholding will trow the second image where car body is not separated correctly. i tried Aforge.net Fill holes image filter but no significant change has been done to the threshold image. I tried to use color filter but it i did not return a correct output due to color vary of the body. can anyone suggest and solution for this?
Original Image
Threshold Image
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可能想要研究聚类,而不是阈值化。
作为快速和肮脏的测试,我增加了 HSB 空间中的图像亮度(使用 Mathematica):
然后我使用了简单的 K-Nearest 聚类:
进行着色以查找图像中相似颜色的簇(还有更多) ,可能更合适的聚类算法,所以你应该尝试一下)。然后我可以调整其中一个簇的颜色:
如果您想使用阈值处理,您可能应该使用 CIE 色彩空间,因为该色彩空间中的欧几里得距离更接近人类的感知。
Instead of thresholding, you might want to look into clustering.
As a quick&dirty test, I've increased the image brightness in HSB space (using Mathematica):
Then I've used simple K-Nearest clustering:
to find clusters of similar colors in the image (there are many more, probably more suitable clustering algorithms, so you should experiment a little). Then I can just adjust the color in one of the clusters:
If you want to use thresholding, you should probably use a CIE color space, since euclidian distances in that color space are closer to human perception.
几年前我有一个类似的项目。我不记得确切的细节,但想法是在图像上移动一个(不太小的)滑动窗口,并计算窗口内每个位置的平均强度(可能分别针对 R、G 和 B)。我用这些平均值填充了“阈值图像”,并从原始图像中减去它。某处存在缩放因子以及其他调整内容,但重点是,这种方法比使用恒定阈值要好得多。
I had a similar project few years ago. I can't remember the exact details, but the idea was to shift a (not too small) sliding window over the image, and calculate the average intensity (maybe for R, G and B separately) inside the window at each position. I filled a "threshold image" with these averages, and subtracted it from the original image. There was a scaling factor somewhere, and other tuning stuff, but the point is, such an approach was way better than using a constant threshold.
如果您要使用一组阈值,则最好在色相饱和度值中选择黄色色调 色彩空间。请参阅相关的SO问题。
If you are going to use a set of thresholds, you might be better of selecting yellow hues in the Hue Saturation Value colorspace. See the related SO question.
给我:
通过查看图像的直方图,我得到了 0.64 阈值。我建议你使用MATLAB进行图像处理,因为它更容易。希望对您为图像着色有所帮助。
Gives me :
I got the 0.64 threshold by looking at the image's histogram. I suggest you use MATLAB to do image processing as it is much easier. Hope that helps you in colouring the image.