private static function runCmplx($func, Image $image): Image
    {
        $original_format = $image->format;

        if ($image->format != 'complex' && $image->format != 'dpcomplex') {
            if ($image->bands % 2 != 0) {
                throw new Exception('not an even number of bands');
            }

            if ($image->format != 'float' && $image->format != 'double') {
                $image = $image->cast('float');
            }

            if ($image->format == 'double') {
                $new_format = 'dpcomplex';
            } else {
                $new_format = 'complex';
            }

            $image = $image->copy(['format' => $new_format,
                                   'bands' => $image->bands / 2]);
        }

        $image = $func($image);

        if ($original_format != 'complex' && $original_format != 'dpcomplex') {
            if ($image->format == 'dpcomplex') {
                $new_format = 'double';
            } else {
                $new_format = 'float';
            }

            $image = $image->copy(['format' => $new_format,
                                   'bands' => $image->bands * 2]);
        }

        return $image;
    }
private static function runCmplx($func, Image $image): Image
    {
        $original_format = $image->format;

        if ($image->format != 'complex' && $image->format != 'dpcomplex') {
            if ($image->bands % 2 != 0) {
                throw new Exception('not an even number of bands');
            }

            if ($image->format != 'float' && $image->format != 'double') {
                $image = $image->cast('float');
            }

            if ($image->format == 'double') {
                $new_format = 'dpcomplex';
            } else {
                $new_format = 'complex';
            }

            $image = $image->copy(['format' => $new_format,
                                   'bands' => $image->bands / 2]);
        }

        $image = $func($image);

        if ($original_format != 'complex' && $original_format != 'dpcomplex') {
            if ($image->format == 'dpcomplex') {
                $new_format = 'double';
            } else {
                $new_format = 'float';
            }

            $image = $image->copy(['format' => $new_format,
                                   'bands' => $image->bands * 2]);
        }

        return $image;
    }
private static function runCmplx ( $ func , Image $ image ) : Image { $ original_format = $ image -> format ; if ( $ image -> format != 'complex' && $ image -> format != 'dpcomplex' ) { if ( $ image -> bands % 2 != 0 ) { throw new Exception ( 'not an even number of bands' ) ; } if ( $ image -> format != 'float' && $ image -> format != 'double' ) { $ image = $ image -> cast ( 'float' ) ; } if ( $ image -> format == 'double' ) { $ new_format = 'dpcomplex' ; } else { $ new_format = 'complex' ; } $ image = $ image -> copy ( [ 'format' => $ new_format , 'bands' => $ image -> bands / 2 ] ) ; } $ image = $ func ( $ image ) ; if ( $ original_format != 'complex' && $ original_format != 'dpcomplex' ) { if ( $ image -> format == 'dpcomplex' ) { $ new_format = 'double' ; } else { $ new_format = 'float' ; } $ image = $ image -> copy ( [ 'format' => $ new_format , 'bands' => $ image -> bands * 2 ] ) ; } return $ image ; }
Run a function expecting a complex image. If the image is not in complex
format, try to make it complex by joining adjacant bands as real and
imaginary.

@param function $filename The function to run.
@param Image    $image    The image to run the function on.

@throws Exception

@return Image A new Image.

@internal
Run a function expecting a complex image . If the image is not in complex format try to make it complex by joining adjacant bands as real and imaginary .