The easiest way to convert your matrix into something you can display elsewhere
is:
wim( $my_matrix, "filename.png" );
If you want to enlarge it you can do something like this:
use PDL::Transform;
$size = pdl($my_matrix->dims)* $some_expansion_factor;
$image = $my_matrix->match( [ $size->list ], {method=>'sample'});
wim($image,"filename.png");
If you want nice borders as in your picture, you can assemble an image pretty
easily with range:
sub enlarge {
my $in = shift;
my $square = shift || 5; # 5x5 pixels by default
my $border = shift || 2; # 2-pixel-wide borders by default
my $isize = pdl($in->dims); # find input
size
my $osize = $isize * ($square+$border) - $border; # calculate
output size (fencepost!)
my $out = zeroes($osize->list) + $in->max; # Generate
output, set to white
my $ndc = ndcoords($isize) * ($square + $border); # Index all
coordinates
$out->range($ndc, [$square,$square]) .= $in; # Stuff
pixel valus into squares
return $out;
}
On Sep 15, 2011, at 3:42 PM, MARK BAKER wrote:
>
> From: MARK BAKER <[email protected]>
> To: Matthew Kenworthy <[email protected]>
> Sent: Thursday, September 15, 2011 2:37 PM
> Subject: Re: [Perldl] Can any one help me on this ???
>
> Hey Matt
>
> I want to be able to take a large matrix of "ones" and "zeros" (about 150000)
> and make a 2D black and white picture ...
>
> for example if i had the matrixg
>
> [0 1 0 1 0 1 0]
> [0 1 1 1 1 1 1]
> [1 1 1 1 1 1 0]
>
> I want to make a Black and white picture like
>
> ■ ■ ■
> ■■■■■■
> ■■■■■■
>
>
> now if you can see that it is some black squares
> and the lack of black squares , and I want to use
> use PDL::Image2D and imagrgb to do it
> im just lacking the the way to go about it properly
> so im doing some reading, I wonder tho if you could
> help me !
>
> Thanks
>
> Mark R Baker
>
>
>
>
>
>
>
>
>
>
>
>
>
> From: Matthew Kenworthy <[email protected]>
> To: MARK BAKER <[email protected]>
> Sent: Thursday, September 15, 2011 2:01 PM
> Subject: Re: [Perldl] Can any one help me on this ???
>
> Mark,
>
> I'm not sure what you're trying to do - do you want to display a 2D
> image on a display?
>
> Matt
>
> On Thu, Sep 15, 2011 at 10:01 PM, MARK BAKER <[email protected]> wrote:
> > ________________
> > I have been trying to get a binary 2D picture where the zeros are black and
> > the ones are white
> > but im having trouble trying to figure out how to put
> >
> > [0 1 0 0 1 1 1 0 1 0 1 0]
> > [0 1 0 1 1 0 1 1 1 0 1 0]
> > [0 1 1 0 1 0 1 0 1 1 1 0]
> >
> > something like this in a black and white picture
> >
> > can any one help me with this ...
> >
> > my attempt at rewriting the lucy demo to it
> > is but I feel really lost here...
> >
> > use PDL; use PDL::Image2D; use PDL::Graphics::TriD;nokeeptwiddling3d;
> >
> >
> > for $x (0..1,1,1,0) {
> > for $y (reverse 0..1,0,0,1) {
> > for $z (reverse 1..999) {
> > $z = 0.001*$z;
> > $d=byte(random(zeroes(1000,100))>$z);
> > $k=byte [[$x,$y,$x,$y],[$y,$y,$x,$y],[$y,$x,$x,$x]];
> > do{ imagrgb [$d];
> > $s=conv2d($d,$k);
> > $d&=($s<5);
> > $d&=($s>1);
> > $d|=($s==3);
> > } while (!twiddle3d);
> > }
> > } }
> >
> > Thanks
> >
> > Mark R Baker
> >
> > ______________________
> > Perldl mailing list
> > [email protected]
> > http://mailman.jach.hawaii.edu/mailman/listinfo/perldl
> >
> >
> >
> > _______________________________________________
> > Perldl mailing list
> > [email protected]
> > http://mailman.jach.hawaii.edu/mailman/listinfo/perldl
> >
> >
>
>
>
> --
> Matthew Kenworthy / Assistant Professor / Leiden Observatory
> Niels Bohrweg 2 (#463) / P.O. Box 9513 / 2300 RA Leiden / NL
>
>
>
>
> _______________________________________________
> Perldl mailing list
> [email protected]
> http://mailman.jach.hawaii.edu/mailman/listinfo/perldl
_______________________________________________
Perldl mailing list
[email protected]
http://mailman.jach.hawaii.edu/mailman/listinfo/perldl