gpt4 book ai didi

image-processing - ComponentMeasurements[_,"Centroid"] 结果偏移

转载 作者:行者123 更新时间:2023-12-04 18:50:50 24 4
gpt4 key购买 nike

我需要获取 质心 (质心)用于一组具有亚像素精度的二值图像中的组件。

Mathematica 8 附带了一个很好的补充:

i =  Import@"http://i.stack.imgur.com/2pxrN.png";  
m1 = ComponentMeasurements[MorphologicalComponents[i], "Centroid"] /.
Rule[_, x_] -> x
(*
-> {{403.229, 453.551}, {660.404, 371.383}, {114.389, 434.646}, {295.5, 206.}}
*)

但是当这些结果显示与其他地方进行的其他计算不一致时,我遇到了一些麻烦。

所以我推出了自己的,也许不太好:
i = Import@"http://i.stack.imgur.com/2pxrN.png";
f[i_] := N@{#[[2]], ImageDimensions[i][[2]] - #[[1]]} & /@
( Mean /@
Function[x, Map[
Position[x, #, 2] &,
Complement[Union@Flatten[x], {0}]]]
[MorphologicalComponents[i]]);
f[i]
Show[i, Graphics[{Red, Disk[#, 10] & /@ f[i]}]]
(*
-> {{403.729, 453.051}, {660.904, 370.883}, {114.889, 434.146}, {296., 205.5}}
*)

enter image description here

您可以看到这些结果之间存在 0.5 的偏移:
Thread[Subtract[m1, f[i]]]
(*
-> {{-0.5, -0.5, -0.5, -0.5}, {0.5, 0.5, 0.5, 0.5}}
*)

起初我认为问题与图像尺寸是偶数或奇数有关,但事实并非如此。

我更喜欢使用 ComponentMeasurements[ ..,"Centroid"]并更正结果,但我担心 future 的 Mma 版本可能会修改此行为并破坏结果。

我还可以使用已知图像运行先前的“校准”并计算偏移量,因此它会自动更正,但我想先了解发生了什么。

这是一个错误吗?
关于为什么会发生这种情况的任何想法?

最佳答案

我觉得文档页面为 ComponentMeasurements包含解决方案:

Position, area, and length measurements are taken in the standard image coordinate system where position {0,0} corresponds to the bottom-left corner, x runs from 0 to width, and y runs from 0 to height.



您正在计算整个像素和 ComponentMeasurements测量像素位置。在这个系统中,左下角像素的中心位于 {1/2,1/2}。

关于image-processing - ComponentMeasurements[_,"Centroid"] 结果偏移,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6471095/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com