How to get TASImage data

Hi
i would like to load an image (.jpg or .bmp) into a matrix, manipulate it and then Draw it on the screen. In principle it works, but for some reasons, i dont get the same result from the two following methods:

void ima(){
    TASImage* im = TASImage::Open("test.jpg");
    TImagePalette pal = im->GetPalette();
    UInt_t w = im->GetWidth();
    UInt_t h = im->GetHeight();    
    TArrayD* arr = im->GetArray(w,h,&pal);
    im->SetImage(arr->fArray,w,h,&pal);
    im->Draw("xyz");
}

and

void ima(){
    TASImage* im = TASImage::Open("test.jpg");
    im->Draw("xyz");
}

I have attached the two pics… would be great if someone could help me




I started from the standard example in the $ROOTSYS/tutorial directory and ended up with:

void ima3()
{
   TImage *img = TImage::Open("test.jpg");

   img->SetConstRatio(0);
   img->SetImageQuality(TAttImage::kImgBest);
   TImage *img5 = (TImage*)img->Clone("img5");
   img5->Vectorize(256);

   TImage *img6 = (TImage*)img->Clone("img6");
   TImagePalette *pal = (TImagePalette *)&img5->GetPalette();
   UInt_t w = img6->GetWidth();
   UInt_t h = img6->GetHeight();
   TArrayD *arr = img6->GetArray(w, h, pal);
   img6->SetImage(arr->GetArray(), w, h, pal);
   img6->Draw();

}

Hi
im sorry for posting without thinking twice…
What i actually wanted to get is the RGB values from the image in matrices and vice versa.
I couldnt find the example you are refering to and also searching the web for TASImage or the ARGB format i couldnt find a “ready for c&p” example. However, here is how it works:

    TASImage* im = TASImage::Open("test.jpg");
    TImagePalette pal = im->GetPalette();
    UInt_t w = im->GetWidth();
    UInt_t h = im->GetHeight();    
    UInt_t* arr = im->GetArgbArray();    
    TMatrixD A(w,h); // (this is the transposed image)
    TMatrixD R(w,h);
    TMatrixD G(w,h);
    TMatrixD B(w,h);
    for (int i=0;i<w;i++){
        for (int j=0;j<h;j++){
            int t = j*w+i;
            UInt_t val = arr[t];
            A[i][j] = (UInt_t)((val >> 24) & 0xFF);
            R[i][j] = (UInt_t)((val >> 16) & 0xFF);
            G[i][j] = (UInt_t)((val >>  8) & 0xFF);
            B[i][j] = (UInt_t)((val      ) & 0xFF);
        }       
    }
    // 
    // ... apply some operations on the matrices ... 
    // 
    for (int i=0;i<w;i++){
        for (int j=0;j<h;j++){
            unsigned int val = ((unsigned int)A[i][j])<<24;
            val = val + (((unsigned int)R[i][j])<<16);
            val = val + (((unsigned int)G[i][j])<<8);
            val = val + ((unsigned int)B[i][j]);
            arr[j*w+i] = val;
        }
    }
    im->Draw("xyz");

it is here:
root.cern.ch/root/html/tutorials … age.C.html