|
Posted by elie on May 7, 2008, 2:47 pm
Please log in for more thread options
thanks ben,
I think perlMagik is the right library to use, I'm going to find an
imageMagic newsgroup to ask around in, I'll post my findings later.
|
|
Posted by Ben Morrow on May 7, 2008, 3:36 pm
Please log in for more thread options
>
> > This is just a brainstorm, :-)
> > but you might be able to do some sort
> > of binary regex search of the larger images. You would have to strip
> > off the png header of the smaller image.
>
> As far as I know, PNG is a compressed format, so it's not possible to access
> the actual pixel data just by "stripping off the png header".
A good way around this is to run the PNG through pngtopnm |
pnmtoplainpnm. ASCII pnm format is very simple (that's the point).
Ben
--
don't get my sympathy hanging out the 15th floor. you've changed the locks 3
times, he still comes reeling though the door, and soon he'll get to you, teach
you how to get to purest hell. you do it to yourself and that's what really
hurts is you do it to yourself just you, you and noone else ** ben@morrow.me.uk
|
|
Posted by elie on May 7, 2008, 4:50 pm
Please log in for more thread options
ben with your method,
pngtopnm | pnmtoplainpnm
I was able to find out if the pattern is there or not.
now i only need to find out the location, any idea how that ASCII maps
to pixels. i need to find out if my pattern is below y pixels or right
of x pixels.
I'll go look for a pnm specification.
|
|
Posted by elie on May 7, 2008, 4:51 pm
Please log in for more thread options thank you for your reply Sinan, I will try your suggestion if the
pngtopnm | pnmtoplainpnm doesn't work.
|
|
Posted by zentara on May 8, 2008, 7:21 am
Please log in for more thread options On Wed, 7 May 2008 23:41:38 +0900, "Ben Bullock"
>
>> This is just a brainstorm, :-)
>> but you might be able to do some sort
>> of binary regex search of the larger images. You would have to strip
>> off the png header of the smaller image.
>
>As far as I know, PNG is a compressed format, so it's not possible to access
>the actual pixel data just by "stripping off the png header".
Well then, you probably can convert each pixel to rgb values, and
compare the following hex data:
Pixel Data looks like:
ffffff00 e7e7ffff e7e7ffff e7e7ffff e7e7ffff e7e7ffff e7e7ffff e7e7ffff
e7e7ffff e7e7ffff e7e7ffff e7e7ffff e7e7ffff e7e7ffff e7e7ffff e7e7ffff
ffffff00 ffffff00 ffffff00 ffffff00
The nice thing about pixel rgb data, is you can then set some
sort of threshold for a close match.
#!/usr/bin/perl
#None of these is fast, mainly because of the overhead of calling Perl
#code for each pixel.
use strict;
my $imagefile = shift or die "No file specified\n";
sub rgba2hex {
sprintf "%02x%02x%02x%02x", map { $_ || 0 } @_;
}
{
use Imager;
my %colors;
my $img = Imager->new();
$img->open( file => $imagefile ) or die $img->errstr;
my ( $w, $h ) = ( $img->getwidth, $img->getheight );
for my $i ( 0 .. $w - 1 ) {
for my $j ( 0 .. $h - 1 ) {
my $color = $img->getpixel( x => $i, y => $j );
my $hcolor = rgba2hex $color->rgba();
print "$hcolor ";
$colors++;
}
}
printf "Imager: Number of colours: %d\n", scalar keys %colors;
}
{
use GD;
my %colors;
my $gd = GD::Image->new($imagefile) or die
"GD::Image->new($imagefile)";
my ( $w, $h ) = $gd->getBounds();
for my $i ( 0 .. $w - 1 ) {
for my $j ( 0 .. $h - 1 ) {
my $index = $gd->getPixel( $i, $j );
my $hcolor = rgba2hex( $gd->rgb($index), 0 );
$colors++;
}
}
printf "GD: Number of colours: %d\n", scalar keys %colors;
}
{
use Image::Magick;
my %colors;
my $img = Image::Magick->new();
my $rc = $img->Read($imagefile);
die $rc if $rc;
my ( $w, $h ) = $img->Get( 'width', 'height' );
for my $i ( 0 .. $w - 1 ) {
for my $j ( 0 .. $h - 1 ) {
my $color = $img->Get("pixel[$i,$j]");
my $hcolor = rgba2hex split /,/, $color;
$colors++;
}
}
printf "Image::Magick: Number of colours: %d\n", scalar keys
%colors;
}
__END__
zentara
--
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html
|
| Similar Threads | Posted | | how to simply parse raw image data and output to an image file ? | January 3, 2008, 11:19 am |
| best way to store binary image data in a variable using image magick | January 25, 2008, 1:17 am |
| binary searching in perl | October 10, 2006, 2:16 pm |
| Image processing in perl? | September 13, 2007, 11:03 pm |
| Searching database with perl script | June 19, 2006, 2:17 pm |
| Is it possible to resize or crop JPG image with Perl? | August 31, 2005, 8:44 am |
| Perl grabbing an external image | December 15, 2005, 2:36 pm |
| perl GD Image resolution problem | May 5, 2008, 11:28 pm |
| searching a "text" in word document using perl | January 28, 2005, 3:38 pm |
| How good is PERL at searching ASCII files? | December 7, 2006, 10:45 am |
|