Click here to Skip to main content
15,919,132 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to read a quickbird multispectral image which is having 16 bits pixel value each for red, green, blue and alpha component. I am reading its pixel values using gdal library but I am not getting the exact values of all 4 layers. I am getting very different image pixel values than the original and I dont know why it is coming so. please help me.........

Below is my code to read quickbird multispectral image....

C++
GDALDataset *hd1; 
GDALRasterBand *Rband, *Gband, *Bband, *Alphaband; 
int widthMS, 
int *Rbuffer, *Gbuffer, *Bbuffer, *Alphabuffer; 
int i,j,k; 
hd1 =(GDALDataset *)GDALOpen("G:\\images\\QB-multispectral-clipd.tif",GA_ReadOnly); 
widthMS = hd1->GetRasterXSize(); 
heightMS = hd1->GetRasterYSize(); 
Rband = hd1->GetRasterBand(1); 
Gband = hd1->GetRasterBand(2); 
Bband = hd1->GetRasterBand(3); 
Alphaband = hd1->GetRasterBand(4); 
Rbuffer = (int*)CPLMalloc(sizeof(int)*widthMS*heightMS); 
Gbuffer = (int*)CPLMalloc(sizeof(int)*widthMS*heightMS); 
Bbuffer = (int*)CPLMalloc(sizeof(int)*widthMS*heightMS); 
Alphabuffer = (int*)CPLMalloc(sizeof(int)*widthMS*heightMS); 
Rband->RasterIO(GF_Read,0,0,widthMS,heightMS,Rbuffer,widthMS,heightMS,GDT_Int32,0,0); 
Gband->RasterIO(GF_Read,0,0,widthMS,heightMS,Gbuffer,widthMS,heightMS,GDT_Int32,0,0); 
Bband->RasterIO(GF_Read,0,0,widthMS,heightMS,Bbuffer,widthMS,heightMS,GDT_Int32,0,0); 
Alphaband->RasterIO(GF_Read,0,0,widthMS,heightMS,Alphabuffer,widthMS,heightMS,GDT_Int32,0,0); 
MSimage = gcnew System::Drawing::Bitmap(widthMS,heightMS,PixelFormat::Format32bppArgb); 
k=0; 
for (j=0;j<heightMS;j++)
{
	for(i=0;i<widthMS;i++)
	{
		Color newclr = Color.FromArgb((unsigned char)(*(Alphabuffer+k)),(unsigned char)(*(Rbuffer+k)),(unsigned char)(*(Gbuffer+k)),(unsigned char)(*(Bbuffer+k)));
		MSimage->SetPixel(i,j,newclr); 
		k++; 
	}
} 
pictureBox2->Image = MSimage;
Posted
Updated 2-Dec-12 18:00pm
v3
Comments
Sergey Alexandrovich Kryukov 1-Dec-12 22:19pm    
I don't think anyone could help you unless you provide some code sample.
--SA
Richa Vats 2-Dec-12 8:12am    
below is the code which i used to read a quickbird multispectral image.....

GDALDataset *hd1;
GDALRasterBand *Rband, *Gband, *Bband, *Alphaband;
int widthMS, heightMS;
int *Rbuffer, *Gbuffer, *Bbuffer, *Alphabuffer;
int i,j,k;
hd1 =(GDALDataset *)GDALOpen("G:\\images\\QB-multispectral-clipd.tif",GA_ReadOnly);
widthMS = hd1->GetRasterXSize();
heightMS = hd1->GetRasterYSize();
Rband = hd1->GetRasterBand(1);
Gband = hd1->GetRasterBand(2);
Bband = hd1->GetRasterBand(3);
Alphaband = hd1->GetRasterBand(4);
Rbuffer = (int*)CPLMalloc(sizeof(int)*widthMS*heightMS);
Gbuffer = (int*)CPLMalloc(sizeof(int)*widthMS*heightMS);
Bbuffer = (int*)CPLMalloc(sizeof(int)*widthMS*heightMS);
Alphabuffer = (int*)CPLMalloc(sizeof(int)*widthMS*heightMS);
Rband->RasterIO(GF_Read,0,0,widthMS,heightMS,Rbuffer,widthMS,heightMS,GDT_Int32,0,0);
Gband->RasterIO(GF_Read,0,0,widthMS,heightMS,Gbuffer,widthMS,heightMS,GDT_Int32,0,0);
Bband->RasterIO(GF_Read,0,0,widthMS,heightMS,Bbuffer,widthMS,heightMS,GDT_Int32,0,0);
Alphaband->RasterIO(GF_Read,0,0,widthMS,heightMS,Alphabuffer,widthMS,heightMS,GDT_Int32,0,0);

MSimage = gcnew System::Drawing::Bitmap(widthMS,heightMS,PixelFormat::Format48bppRgb);
k=0;
for (j=0;j<heightms;j++)
{
for="" (i="0;i<widthMS;i++)
" {
="" color="" newclr="Color::FromArgb(*(Rbuffer+k),*(Gbuffer+k),*(Bbuffer+k),*" (alphabuffer+k));
="" msimage-="">SetPixel(i,j,newclr);
k++;
}
}
pictureBox2->Image = MSimage;
Sergey Alexandrovich Kryukov 2-Dec-12 13:47pm    
To make it readable, could you move it in the body of the question, using "Improve question" above?
To format code property, you need to inclose it in the HTML tag "pre" with the attribute lang="cs". But this does not work in comments.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900