KEVIVI
KEVIVI

Reputation: 57

Pixel-wise operations - ImageCallFunctionAtPositions

There are new script functions in GMS 3.4.x for pixel-wise operations. Can someone give short examples on how to utilize these functions?

Thanks!

Upvotes: 0

Views: 84

Answers (1)

BmyGuest
BmyGuest

Reputation: 2949

The script commands are documented in the F1 help documentation under:

F1 help

An example can also be found in the Examples section of the documentation, from which I've copied it here:

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" )

A minimalistic example for ImageReplaceByFunctionAtPositions() is the following:

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()
 

Upvotes: 0

Related Questions