NAME

OME::Tasks::ImageManager - utility methods to manage images

Back to Top


SYNOPSIS

        use OME::Tasks::ImageManager;
        my $imageManager = OME::Tasks::ImageManager->new();

Back to Top


DESCRIPTION

OME::Tasks::ImageManager provides utility methods to manage images

Back to Top


METHODS (ALPHABETICAL ORDER)

delete ($id)

Delete Image from database

getAllImages ()

        my @images = $imageManager->getAllImages();

Get all the images in the database.

getAllImageCount ()

        my $i_count = $imageManager->getAllImageCount();

Gets a count of all the images in the database.

getUserImages ($experimenter)

        my @user_images = $imageManager->getUserImages();
        my @other_user_images = $imageManager->getUserImages(
                $other_experimenter
        );

Get all the images related to an experimenter.

Note: The method uses the Session's experimenter as a filter if none is specified.

getUserImageCount ()

        my $i_count = $imageManager->getUserImageCount();
        my $other_i_count = $imageManager->getUserImageCount(
                $other_experimenter
        );

Gets a count of all the images owner by a user.

Note: The method uses the Session's experimenter as a filter if none is specified.

listMatching ($ref,$used,$datasetID)

datasetID (optional) if not defined dataset=current dataset ref=ref array list group_id (optional)

Images in Research group if used defined, images in Research group not already used by project

load ($imageID)

Load image object Return: image object

manage

ref =ref array list of group_id

Informations to manage images Return: ref hash (GroupImagesInfo,UserImagesInfo)

GroupImagesInfo: Check images used in others projects i.e. not user's project key:image_id => value: image_name

UserImagesInfo: hash of hashes: key: image_id ->{list}=> ref hash datasetInfo (i.e. key:dataset_id value: dataset object ->{remove}=> ref hash dataset_id value booleen ->{image} => image object;

remove ($ref)

Remove image from datasets

deleteCurrentAnnotation

        OME::Tasks::ImageManager->deleteCurrentAnnotation( $image );

This tries to get an annotation from getCurrentAnnotationgetCurrentAnnotation() If it gets one that belongs to the current user, it will mark it invalid.

getCurrentAnnotation

        my $imageAnnotation = OME::Tasks::ImageManager->
            getCurrentAnnotation( $image );

This will look for the most recent ImageAnnotation created by the current user that is marked Valid. Failing to that, it will look for the most recent ImageAnnotation created by anyone that is marked Valid.

If no Valid ImageAnnotations are found, an undef will be returned.

writeAnnotation

        my $imageAnnotation = OME::Tasks::ImageManager->
            writeAnnotation( $image, $data_hash );

This will write a new ImageAnnotation attribute. The data_hash should follow the format for factory NewObject calls. e.g. { Content => $content, ... } If the Content is identical to the current annotation, a new ImageAnnoation attribute will not be created, and the current annotation will be returned.

If this user has a current annotation on this image, the other annotation will be marked invalid. If another user has a current annotation on this image, the other user's annotation will be left alone.

Note, this method does NOT commit the db transaction.

getThumbURL

        # retrieve the URL for the thumbnail of the default pixels of a given image
        my $thumbnailURL = $imageManager->getThumbURL($image);
        # retrieve the URL for the thumbnail of the default pixels of a given image_id
        my $thumbnailURL = $imageManager->getThumbURL($imageID);

Will return undef if there is not a default pixels associated with the image.

chownImage

        OME::Tasks::ImageManager->chownImage($image,user=>$user,group=>$group);
        OME::Tasks::ImageManager->chownImage($image,group_id=>$group->id());
        # Make the Image public
        OME::Tasks::ImageManager->chownImage($image,group_id=>undef);
        # this doesn't do anything but returns true if the call would be successfull otherwise
        my $canChown = OME::Tasks::ImageManager->chownImage($image, group_id=>undef, try=>1);

Changes the group and experimenter owner of the image and its import MEX. The OME::Session owner must either be superuser, leader of the group of the image and mex owner, or the experimenter owner of the image and mex.

getImageOriginalFiles

        my $originalFiles = OME::Tasks::ImageManager->getImageOriginalFiles($image);

collects original files attributes for a given image. If none are found, returns undef. If one is found, returns it. If a bunch are found, returns a list.

getImageByOriginalFile

        my $image = OME::Tasks::ImageManager->getImageByOriginalFile($originalFile);

figures out what OME image an OriginalFile produced =cut

sub getImageByOriginalFile{
my ($self,$originalFile)=@_ ;
my $session=$self->__Session();
my $factory=$session->Factory();


        my $ImageImport = $factory->findObject( "OME::Module", name => 'Image import');
        my $ImageImportFI = $factory->findObject( "OME::Module::FormalInput",
                                                                        module_id => $ImageImport->id(),
                                                                        name       => 'Files' );

        # First construct a query that assumes all original files uploaded with this 
        # original file were consumed by a single image import.
        # ai points to the ImportImage module that was fed the OriginalFiles Attribute as input
        my $ai = $factory->findObject( "OME::ModuleExecution::ActualInput", 
                                                input_module_execution => $originalFile->module_execution_id(),
                                                formal_input_id => $ImageImportFI->id());
        # If that query didn't turn up anything, then construct a second one that 
        # assumes this original file was wrapped with a virtual module execution, and
        # consumed by a different image import than some of its siblings.
        unless( $ai ) {
                $ai = $factory->
                        findObject( "OME::ModuleExecution::ActualInput", 
                                'input_module_execution.virtual_outputs.attribute_id' => $originalFile->id(),
                                formal_input_id => $ImageImportFI->id()
                        );
        }
        # If that query also failed, then this original files wasn't used to import
        # an image.
        return undef
                unless( $ai );

        # the ImportImage module reveals the image
        return  $ai->module_execution()->image();
}

sub getDisplayOptions{
my ($self,$image,$pixels)=@_ ;
$pixels = $image->DefaultPixels()
unless $pixels;
my $session=$self->__Session();
my $factory=$session->Factory();
my ($theZ,$theT,$isRGB,@cbw,@rgbOn);
my $displayOptions = OME::Tasks::PixelsManager->getDisplayOptions( $pixels );
my %h =();
$theZ=($displayOptions->ZStart() + $displayOptions->ZStop() ) / 2;
$theT=($displayOptions->TStart() + $displayOptions->TStop() ) / 2;
$isRGB= $displayOptions->DisplayRGB();
@cbw=(
$displayOptions->RedChannel()->ChannelNumber(),
$displayOptions->RedChannel()->BlackLevel(),
$displayOptions->RedChannel()->WhiteLevel(),
$displayOptions->GreenChannel()->ChannelNumber(),
$displayOptions->GreenChannel()->BlackLevel(),
$displayOptions->GreenChannel()->WhiteLevel(),
$displayOptions->BlueChannel()->ChannelNumber(),
$displayOptions->BlueChannel()->BlackLevel(),
$displayOptions->BlueChannel()->WhiteLevel(),
$displayOptions->GreyChannel()->ChannelNumber(),
$displayOptions->GreyChannel()->BlackLevel(),
$displayOptions->GreyChannel()->WhiteLevel(),
);
push (@rgbOn,$displayOptions->RedChannelOn(),$displayOptions->GreenChannelOn(),$displayOptions->BlueChannelOn());
%h=(
'theZ' => $theZ,
'theT' => $theT,
'isRGB' => $isRGB,
'CBW' => \@cbw,
'RGBon' =>\@rgbOn
);
return \%h;

} #################### # PRIVATE METHODS # ####################

sub checkDuplicate{ my ($ref)=@_; my %seen=(); my $object; my @a=(); foreach $object (@$ref){ my $id=$object->id(); push(@a,$object) unless $seen{$id}++; } return \@a; }

sub deleteImage{
my ($id,$db)=@_;
my $table="images";
my ($condition,$result);
$condition="image_id=".$id;
$result=do_delete($table,$condition,$db);
return (defined $result)?1:undef;

}

sub deleteInMap{ my ($session,$id,$db)=@_; my @tables=(); #existing @tables=qw(image_dataset_map ome_sessions_images); #last one just in case! # dynamic my @tablesDynamic=$session->Factory()->findObjects("OME::DataTable",'granularity'=>'I'); my @dynamic=(); foreach (@tablesDynamic){ my $tablename=lc($_->table_name()); push(@dynamic,$tablename) unless $tablename eq "image_pixels"; } push(@tables,@dynamic); foreach (@tables){ my ($condition,$result); $condition="image_id=".$id; $result=do_delete($_,$condition,$db); return undef unless (defined $result); } # must add a delete cascade # table images + image_pixels. return 1; }

sub notMyProject{ my ($session,$ref)=@_; my @groupProjects=(); if (defined $ref){ foreach (@$ref){ push(@groupProjects,$session->Factory()->findObjects("OME::Project",'group_id'=> $_)); } }else{ @groupProjects=$session->Factory()->findObjects("OME::Project"); } my @myProjects=$session->Factory()->findObjects("OME::Project",'owner_id'=> $session->User()->id()); my $result=notUsed(\@groupProjects,\@myProjects); return ($result,\@myProjects); }

sub notUsed{
my ($refa,$refb)=@_;
my %in_b=();
my @only_a=();
foreach (@$refb){
$in_b{$_->id()}=1;
}
foreach (@$refa){
push(@only_a,$_) unless exists $in_b{$_->id()};
}
return scalar(@only_a)==0?undef:\@only_a;

}

sub notUsedImages{
my ($refa,$refb)=@_;
my %in_b=();
my @only_a=();
foreach (@$refb){
$in_b{$_->id()}=1;
}
foreach (@$refa){
push(@only_a,$_) unless exists $in_b{$_->id()};
}
return scalar(@only_a)==0?undef:\@only_a;

}

sub removeImage{ my ($id,$datasetID,$db)=@_; my ($condition,$result); my $table="image_dataset_map"; $condition="image_id=".$id." AND dataset_id=".$datasetID; $result=do_delete($table,$condition,$db); return (defined $result)?1:undef;

} sub usedDatasetImage{ my ($session,$result,$projects)=@_; my %gpDatasets=(); my %gpImages=(); my %userImages=(); if (defined $result){ foreach (@$result){ my @datasets=();#$_->datasets(); my @dMaps=$session->Factory()->findObjects("OME::Project::DatasetMap",'project_id'=>$_->id() ); foreach my $d (@dMaps){ push(@datasets,$d->dataset()); } foreach my $obj (@datasets){ $gpDatasets{$obj->id()}=$obj unless (exists $gpDatasets{$obj->id()}); my @images=(); my @dMaps=$session->Factory()->findObjects("OME::Image::DatasetMap",'dataset_id'=>$obj->id() ); foreach my $d (@dMaps){ push(@images,$d->image()); }

                #my @images=$obj->images();
                foreach my $i (@images){
                  $gpImages{$i->id()}=$i->name() unless (exists $gpImages{$i->id()});
                }
            }
          } 
        }
        
        foreach (@$projects){
                my @datasets=();
                my @dMaps=$session->Factory()->findObjects("OME::Project::DatasetMap",'project_id'=>$_->id() );
                foreach my $d (@dMaps){
                 push(@datasets,$d->dataset());
                }
 
                # my @datasets=$_->datasets();
                  foreach my $dataset (@datasets){
                    my %datasetInfo=();
            my %remove=();
                    $datasetInfo{$dataset->id()}=$dataset;
                    if (exists $gpDatasets{$dataset->id()} || $dataset->locked()){
                        $remove{$dataset->id()}=undef ;
                   }else{
                        $remove{$dataset->id()}=1 ;
           }
               my @list=$session->Factory()->findObjects("OME::Image::DatasetMap",'dataset_id'=>$dataset->id() );
               my @images=();
                   foreach my $l (@list){
                     push(@images,$l->image());
                   }
                   foreach my $i (@images){
                        if (exists($userImages{$i->id()})){
                          my $list=$userImages{$i->id()}->{list};
                  my %fusion=();
                          %fusion=(%$list,%datasetInfo);
                          $userImages{$i->id()}->{list}=\%fusion;
                          my $rem=$userImages{$i->id()}->{remove};
                  my %mix=();
                          %mix=(%$rem,%remove);
                          $userImages{$i->id()}->{remove}=\%mix;
                        }else{
                          $userImages{$i->id()}->{list}=\%datasetInfo;
                          $userImages{$i->id()}->{remove}=\%remove;
                          $userImages{$i->id()}->{image}=$i;
                        }

                 }
            }
        }
        return (\%gpImages,\%userImages);
}

sub __Session { return OME::Session->instance() }

sub do_delete{ my ($table,$condition,$db)=@_; my $result; if (defined $db){ $result=$db->DeleteRecord($table,$condition); } return $result; }

Back to Top


AUTHOR

JMarie Burel (jburel@dundee.ac.uk)

Back to Top


SEE ALSO

OME::DBObject, OME::Factory, OME::SetDB,

Back to Top