逐像素操作 - ImageCallFunctionAtPositions
Pixel-wise operations - ImageCallFunctionAtPositions
GMS 3 中有新的脚本函数。4.x 用于像素级操作。有人可以举一些简短的例子来说明如何使用这些功能吗?
void ImageCallFunctionAtPositions( BasicImage src, BasicImage mask,
ScriptObject obj, String funName )
RealImage ImageEvaluateFunctionAtPositions( BasicImage src,
BasicImage mask, ScriptObject obj, String funName )
void ImageReplaceByFunctionAtPositions( BasicImage src, BasicImage
mask, ScriptObject obj, String funName )
谢谢!
脚本命令记录在 F1 帮助文档中:
也可以在文档的“示例”部分找到示例,我已将其复制到此处:
class CPointLister
{
image xylist
number count
void AddNonZeroPoint( object self , image src , number px , number py )
{
if ( 0 != sum( src[ px , py ] ) )
{
xylist[ 0 ,count ] = px
xylist[ 1 ,count ] = py
xylist[ 2 ,count ] = src[ px , py ]
count++
}
}
image GetNonZeroPointsXY( object self , image input )
{
count = 0
image mask = !!input // 1 for non-zero points, 0 else
number nPts = sum( mask )
xylist := RealImage( "XY maskpoints" , 4 , 3 , nPts )
ImageCallFunctionAtPositions( input , mask , self , "AddNonZeroPoint" )
return xylist
}
}
image test := realimage( "Test image" , 4 , 512 , 512 )
test = random() < 0.001 ? random() * 100 : 0
test.ShowImage()
image pointList := Alloc( CPointLister ).GetNonZeroPointsXY( test )
pointList.ShowImage()
pointList.ImageGetImageDisplay( 0 ).ImageDisplayChangeDisplayType( "spreadsheet" )
ImageReplaceByFunctionAtPositions() 的简约示例如下:
class CPixeltimer
{
number st
CPixelTimer(object self) { st = GetHighResTickCount(); }
number Timing(object self, image src , number px , number py )
{
return (GetHighResTickCount() - st)/GetHighResTicksPerSecond()
}
}
image test1 := realimage( "Test image 1 - inplace " , 4 , 512 , 512 )
test1.ShowImage()
test1.ImageReplaceByFunctionAtPositions( Alloc(CPixelTimer), "Timing")
image test2 := realimage( "Test image 2 " , 4 , 512 , 512 )
test2 = random()
image mask = test2*0 +(iradius<100 ? 1 : 0)
image test3 := test2.ImageEvaluateFunctionAtPositions( mask, Alloc(CPixelTimer), "Timing")
test3.Setname("Test image 3 - masked evaluation")
test3.ShowImage()
GMS 3 中有新的脚本函数。4.x 用于像素级操作。有人可以举一些简短的例子来说明如何使用这些功能吗?
void ImageCallFunctionAtPositions( BasicImage src, BasicImage mask, ScriptObject obj, String funName )
RealImage ImageEvaluateFunctionAtPositions( BasicImage src, BasicImage mask, ScriptObject obj, String funName )
void ImageReplaceByFunctionAtPositions( BasicImage src, BasicImage mask, ScriptObject obj, String funName )
谢谢!
脚本命令记录在 F1 帮助文档中:
也可以在文档的“示例”部分找到示例,我已将其复制到此处:
class CPointLister
{
image xylist
number count
void AddNonZeroPoint( object self , image src , number px , number py )
{
if ( 0 != sum( src[ px , py ] ) )
{
xylist[ 0 ,count ] = px
xylist[ 1 ,count ] = py
xylist[ 2 ,count ] = src[ px , py ]
count++
}
}
image GetNonZeroPointsXY( object self , image input )
{
count = 0
image mask = !!input // 1 for non-zero points, 0 else
number nPts = sum( mask )
xylist := RealImage( "XY maskpoints" , 4 , 3 , nPts )
ImageCallFunctionAtPositions( input , mask , self , "AddNonZeroPoint" )
return xylist
}
}
image test := realimage( "Test image" , 4 , 512 , 512 )
test = random() < 0.001 ? random() * 100 : 0
test.ShowImage()
image pointList := Alloc( CPointLister ).GetNonZeroPointsXY( test )
pointList.ShowImage()
pointList.ImageGetImageDisplay( 0 ).ImageDisplayChangeDisplayType( "spreadsheet" )
ImageReplaceByFunctionAtPositions() 的简约示例如下:
class CPixeltimer
{
number st
CPixelTimer(object self) { st = GetHighResTickCount(); }
number Timing(object self, image src , number px , number py )
{
return (GetHighResTickCount() - st)/GetHighResTicksPerSecond()
}
}
image test1 := realimage( "Test image 1 - inplace " , 4 , 512 , 512 )
test1.ShowImage()
test1.ImageReplaceByFunctionAtPositions( Alloc(CPixelTimer), "Timing")
image test2 := realimage( "Test image 2 " , 4 , 512 , 512 )
test2 = random()
image mask = test2*0 +(iradius<100 ? 1 : 0)
image test3 := test2.ImageEvaluateFunctionAtPositions( mask, Alloc(CPixelTimer), "Timing")
test3.Setname("Test image 3 - masked evaluation")
test3.ShowImage()