On Mon, 26 Feb 2007 12:13:10 -0500
zentara <[EMAIL PROTECTED]> wrote:

>On Sun, 25 Feb 2007 14:52:25 -0500
>"Scott White" <[EMAIL PROTECTED]> wrote:

>I ran into the same problem when I tried to display a sample DICOM,
>it says 
>
>" Attempt to draw a drawable with depth 16 to a drawable with depth 24"
>
>As I played around, it seems the default depth for the Viewport I tried to
>write to is 24, and I can't find a place to change it. So I'm guessing you 
>need to
>unpack the 16 bit file and repack it as 24?  And there is the problem of
>lopping of the header, to get to the actual data. If anyone is interested in
>playing with this, here is a free sample DICOM image and it's info file.
>http://barre.nom.fr/medical/samples/files/CT-MONO2-16-brain.gz
>http://barre.nom.fr/medical/samples/files/CT-MONO2-16-brain.txt

Well, I'm probably sticking my neck out here, but I love getting
slapped down as long as you edify me. :-)

I took a feeble shot at it, and have some results that may help someone.
I used the dctoraw utility from the dicomtools to strip the header, to get
the raw pixel block. See:
 
http://www.dclunie.com/dicom3tools/workinprogress/dicom3tools_1.00.snapshot.20070202b.tar.bz2
 
 
For the impatient, I've posted the  CT-MONO2-16-brain.raw  file
at   http://zentara.net/perlplay/DICOM 
so you can try the script below.

This script displays the file properly, except the colors are way off.
The pack unpack may need tweaking or I was just lucky. :-)

Anyways, I think you might be able to use pixbuf, if you can figure out
how to do the unpack-pack better than me. :-)  And there still is the tricky
problem of using Perl to strip the unweildy DICOM header.

#!/usr/bin/perl
use strict;
use warnings;
use Gtk2 '-init';
use Glib qw/TRUE FALSE/;

#my $file = shift || die "Need an dicon file as argument $!\n";
my $file = 'CT-MONO2-16-brain.raw';

my $data;
open (FH,"< $file");
read( FH, $data, -s FH );
close FH;
print length $data,"\n";

my $mw = Gtk2::Window->new;
$mw->signal_connect('destroy', sub { Gtk2->main_quit });

$mw->resize(500,500);

my $vbox = Gtk2::VBox->new( FALSE, 6 );
$mw->add($vbox);
$vbox->set_border_width(2);

my $sw = Gtk2::ScrolledWindow->new(undef, undef);
$sw->set_policy('automatic','automatic');
$vbox->pack_start($sw,TRUE,TRUE,0);

my $vp = Gtk2::Viewport->new(undef, undef);
$sw->add($vp);


my $ha = Gtk2::Adjustment->new(50, 0, 1, 0.1, 0.9, 1);
my $va = Gtk2::Adjustment->new(50, 0, 1, 0.1, 0.9, 1);

$sw->set_hadjustment($ha);
$sw->set_vadjustment($va);


my $button = Gtk2::Button->new ('Load');
$button->signal_connect (clicked => \&load_image );
$vbox->pack_end($button,FALSE,FALSE,0);

$mw->show_all();
Gtk2->main;

##########################################################
sub load_image {

my $width = 512;
my $height = 512;

# crappy attempt to convert
my @nums = unpack("(B16)*",$data);
#print "@nums\n";
my @nums1 = map{ pack("(B24)*",$_) } @nums;
$data = join '', @nums1;

my $pixbuf = Gtk2::Gdk::Pixbuf->new_from_data
                ($data,      # the data.  this will be copied.
                'rgb',       # only currently supported colorspace
                0,           # true, because we do have alpha channel data
                8,           # gdk-pixbuf currently allows only 8-bit samples
                $width,      # width in pixels
                $height,     # height in pixels
                $width * 3); # rowstride -- we have RGB data, so it's 3
                             # bytes per pixel.

my $img = Gtk2::Image->new();
$img->set_from_pixbuf($pixbuf);

$vp->add($img);

$mw->show_all();

return 1;
}

__END__


zentara

-- 
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html
_______________________________________________
gtk-perl-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/gtk-perl-list

Reply via email to