DM脚本中是否有累积和功能?

时间:2016-05-12 14:48:53

标签: image-processing projection dm-script

我想沿图像数据的x或y方向做累积和。 Matlib中的“cumsum”中的DM脚本是否有任何功能? 谢谢!

例如像素值为4x4像素的图像

1 2 3 4
2 3 4 5
3 4 5 6
4 5 6 7

沿x方向的累积和将导致:

1 1+2=3 1+2+3=6 1+2+3+4=10
2 5 9 14
3 7 12 18
4 9 15 22 

3 个答案:

答案 0 :(得分:1)

有不同的方法可以实现这一目标,但最快和最简单的方法是创建图像的“完全分箱”版本。

image img := GetFrontImage()
number sizeX, sizeY
img.GetSize( sizeX, sizeY )

image vSum = Rebin( img, 1, sizeY )
image hSum = Rebin( img, sizeX, 1 )
vSum.SetName( "vertical sum" )
vSum.ShowImage()
hSum.SetName( "horizontal sum" )
hSum.ShowImage()

如果你想要一个2D图像,每个像素保持左边所有像素的总和,你可以通过添加偏移图像来实现这一点:

image img := GetFrontImage()
number sizeX, sizeY
img.GetSize( sizeX, sizeY )

image vCumSum := img.ImageClone() 
for( number x = 1; x<sizeX ; x++ )
{
    hCumSum += offset( img, -x, 0 )
}
hCumSum.SetName( "horizontal sum (cumulative)" )
hCumSum.ShowImage()

或者,您可以使用内在变量创建表达式,如

image img := GetFrontImage()
image hCumSum := 0 * img.ImageClone() 
hCumSum += img[icol,irow] + hCumSum[ icol - 1, irow ]
hCumSum.SetName( "horizontal sum (cumulative)" )
hCumSum.ShowImage()

答案 1 :(得分:0)

进行投影的另一种方法是通过矩阵乘法。将2-D图像乘以1的1-D矩阵将图像投影到1-D累积上。

number d0, d1
image HProject, VProject, ones, img
img:=getfrontImage()
img.getSize(d0,d1)
ones:=exprSize(1,d0,1) 
HProject=MatrixMultiply(img,ones)
HProject.rotateLeft()
HProject.showImage()
ones:=exprSize(d1,1,1)
VProject=MatrixMultiply(ones,img)
VProject.showImage()

答案 2 :(得分:0)

我也有一个

image cumsum(image img)
//  computes the cumulative sum along x direction
{
    number sx, sy
    img.GetSize(sx,sy)

    for(number i=1; i<sx; i++)
    {
        img[0,i,sy,i+1]=img[0,i-1,sy,i]+img[0,i,sy,i+1]
    }
    return img
}

image im=getfrontimage()
im=im.cumsum()
im.showimage()