我想知道如何从这种图像中获得边界。
例如:
我正在寻找使用
转换一些图像if
但这只会给我特别重的图像。
在这种情况下,使用x_coord和y_coord我可以创建一个简单的对象。
image <- as(x, 'SpatialGridDataFrame')
我希望为示例添加的圆形png获得一组x_coord和y_coord。
答案 0 :(得分:1)
您可以使用pixsets方法(在 imager 包中)识别给定图像中圆的边缘,如下所示:
px <- im > 0.6 #Select pixels of the circle (i.e., those with high luminance)
plot(px)
现在,当您绘制px
时,将得到以下信息:
要获取像素的坐标,请使用以下命令:
coord <- where(px)
head(coord)
这会给你这样的东西:
# x y cc
#1 1 1 1
#2 2 1 1
#3 3 1 1
#4 4 1 1
#5 5 1 1
#6 6 1 1
要获取界限,请使用以下内容:
boundaries <- boundary(px)
boundaries.xy <- where(boundaries)
head(boundaries.xy)
为您提供以下内容:
# x y cc
#1 103 64 1
#2 102 65 1
#3 104 65 1
#4 103 66 1
#5 185 71 1
#6 184 72 1
您甚至可以如下保存圆形像素:
px_image <- as.cimg(px)
save.image(px_image, "px_image.jpg")
希望有帮助。