  # ------- Create image data of same dimension with only zeroes
        my $result = zeroes(byte(),3,$img-&gt;dims);

        # ------- Assign image data to choosen channel
        my %c = ( red=&gt;0, green=&gt;1, blue=&gt;2 );
        for(my $i=0; $i&lt;3; $i++) {
                if($i == $c{$color}) { $result(($i),:,:) .= $img; }     # PDL::NiceSlice
        }
        return ($result); # Return new image
 }</code></pre>

<h2 id="data-read_png-filename">$data = read_png($filename);</h2>

<p>Reads an imag