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
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");