本文整理汇总了C++中GDALColorTable::GetPaletteInterpretation方法的典型用法代码示例。如果您正苦于以下问题:C++ GDALColorTable::GetPaletteInterpretation方法的具体用法?C++ GDALColorTable::GetPaletteInterpretation怎么用?C++ GDALColorTable::GetPaletteInterpretation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GDALColorTable
的用法示例。
在下文中一共展示了GDALColorTable::GetPaletteInterpretation方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: loadImage
//.........这里部分代码省略.........
case GCI_CyanBand:
theType = GdalAdapter::Cmyk;
ixC = i;
break;
case GCI_MagentaBand:
theType = GdalAdapter::Cmyk;
ixM = i;
break;
case GCI_YellowBand:
theType = GdalAdapter::Cmyk;
ixY = i;
break;
case GCI_BlackBand:
theType = GdalAdapter::Cmyk;
ixK = i;
break;
case GCI_YCbCr_YBand:
theType = GdalAdapter::YUV;
ixYuvY = i;
break;
case GCI_YCbCr_CbBand:
theType = GdalAdapter::YUV;
ixYuvU = i;
break;
case GCI_YCbCr_CrBand:
theType = GdalAdapter::YUV;
ixYuvV = i;
break;
case GCI_AlphaBand:
ixA = i;
break;
case GCI_PaletteIndex:
colTable = poBand->GetColorTable();
switch (colTable->GetPaletteInterpretation())
{
case GPI_Gray :
theType = GdalAdapter::Palette_Gray;
break;
case GPI_RGB :
theType = GdalAdapter::Palette_RGBA;
break;
case GPI_CMYK :
theType = GdalAdapter::Palette_CMYK;
break;
case GPI_HLS :
theType = GdalAdapter::Palette_HLS;
break;
}
break;
}
}
QSize theImgSize(poDataset->GetRasterXSize(), poDataset->GetRasterYSize());
QImage theImg = QImage(theImgSize, QImage::Format_ARGB32);
// Make sure that lineBuf holds one whole line of data.
float *lineBuf;
lineBuf = (float *) CPLMalloc(theImgSize.width() * bandCount * sizeof(float));
int px, py;
//every row loop
for (int row = 0; row < theImgSize.height(); row++) {
py = row;
poDataset->RasterIO( GF_Read, 0, row, theImgSize.width(), 1, lineBuf, theImgSize.width(), 1, GDT_Float32,
bandCount, NULL, sizeof(float) * bandCount, 0, sizeof(float) );
// every pixel in row.
示例2: Mat
cv::Mat KGDAL2CV::ImgReadByGDAL(GDALRasterBand* pBand, int xStart, int yStart, int xWidth, int yWidth)
{
m_width = pBand->GetXSize();
m_height = pBand->GetYSize();
m_nBand = 1;
// check if we have a color palette
int tempType;
if (pBand->GetColorInterpretation() == GCI_PaletteIndex){
// remember that we have a color palette
hasColorTable = true;
// if the color tables does not exist, then we failed
if (pBand->GetColorTable() == NULL){
return cv::Mat();
}
// otherwise, get the pixeltype
// convert the palette interpretation to opencv type
tempType = gdalPaletteInterpretation2OpenCV(pBand->GetColorTable()->GetPaletteInterpretation(), pBand->GetRasterDataType());
if (tempType == -1){
return cv::Mat();
}
m_type = tempType;
}
// otherwise, we have standard channels
else{
// remember that we don't have a color table
hasColorTable = false;
// convert the datatype to opencv
tempType = gdal2opencv(pBand->GetRasterDataType(), m_nBand);
if (tempType == -1){
return cv::Mat();
}
m_type = tempType;
}
if (xStart < 0 || yStart < 0 || xWidth < 1 || yWidth < 1 || xStart > m_width - 1 || yStart > m_height - 1) return cv::Mat();
if (xStart + xWidth > m_width)
{
std::cout << "The specified width is invalid, Automatic optimization is executed!" << std::endl;
xWidth = m_width - xStart;
}
if (yStart + yWidth > m_height)
{
std::cout << "The specified height is invalid, Automatic optimization is executed!" << std::endl;
yWidth = m_height - yStart;
}
cv::Mat img(yWidth, xWidth, m_type, cv::Scalar::all(0.f));
// iterate over each raster band
// note that OpenCV does bgr rather than rgb
GDALColorTable* gdalColorTable = NULL;
if (pBand->GetColorTable() != NULL){
gdalColorTable = pBand->GetColorTable();
}
const GDALDataType gdalType = pBand->GetRasterDataType();
//if (m_nBand > img.channels()){
// m_nBand = img.channels();
//}
for (int c = 0; c < img.channels(); c++){
// grab the raster size
if (hasColorTable && gdalColorTable->GetPaletteInterpretation() == GPI_RGB) c = img.channels() - 1;
// create a temporary scanline pointer to store data
double* scanline = new double[xWidth];
// iterate over each row and column
for (int y = 0; y<yWidth; y++){
// get the entire row
pBand->RasterIO(GF_Read, xStart, y + yStart, xWidth, 1, scanline, xWidth, 1, GDT_Float64, 0, 0);
// set inside the image
for (int x = 0; x<xWidth; x++){
// set depending on image types
// given boost, I would use enable_if to speed up. Avoid for now.
if (hasColorTable == false){
write_pixel(scanline[x], gdalType, m_nBand, img, y, x, c);
}
else{
write_ctable_pixel(scanline[x], gdalType, gdalColorTable, img, y, x, c);
}
}
}
// delete our temp pointer
delete[] scanline;
}
return img;
}
示例3: img
cv::Mat KGDAL2CV::ImgReadByGDAL(cv::String filename, int xStart, int yStart, int xWidth, int yWidth, bool beReadFourth)
{
m_filename = filename;
if (!readHeader()) return cv::Mat();
int tempType = m_type;
if (xStart < 0 || yStart < 0 || xWidth < 1 || yWidth < 1 || xStart > m_width - 1 || yStart > m_height - 1) return cv::Mat();
if (xStart + xWidth > m_width)
{
std::cout << "The specified width is invalid, Automatic optimization is executed!" << std::endl;
xWidth = m_width - xStart;
}
if (yStart + yWidth > m_height)
{
std::cout << "The specified height is invalid, Automatic optimization is executed!" << std::endl;
yWidth = m_height - yStart;
}
if (!beReadFourth && 4 == m_nBand)
{
for (unsigned int index = CV_8S; index < CV_USRTYPE1; ++index)
{
if (CV_MAKETYPE(index, m_nBand) == m_type)
{
std::cout << "We won't read the fourth band unless it's datatype is GDT_Byte!" << std::endl;
//tempType = -1;
tempType = tempType - ((3 << CV_CN_SHIFT) - (2 << CV_CN_SHIFT));
break;
//tempType = CV_MAKETYPE(index, m_nBand);
}
}
}
cv::Mat img(yWidth, xWidth, tempType, cv::Scalar::all(0.f));
// iterate over each raster band
// note that OpenCV does bgr rather than rgb
int nChannels = m_dataset->GetRasterCount();
GDALColorTable* gdalColorTable = NULL;
if (m_dataset->GetRasterBand(1)->GetColorTable() != NULL){
gdalColorTable = m_dataset->GetRasterBand(1)->GetColorTable();
}
const GDALDataType gdalType = m_dataset->GetRasterBand(1)->GetRasterDataType();
//if (nChannels > img.channels()){
// nChannels = img.channels();
//}
for (int c = 0; c < img.channels(); c++){
int realBandIndex = c;
// get the GDAL Band
GDALRasterBand* band = m_dataset->GetRasterBand(c + 1);
//if (hasColorTable == false){
if (GCI_RedBand == band->GetColorInterpretation()) realBandIndex = 2;
if (GCI_GreenBand == band->GetColorInterpretation()) realBandIndex = 1;
if (GCI_BlueBand == band->GetColorInterpretation()) realBandIndex = 0;
//}
if (hasColorTable && gdalColorTable->GetPaletteInterpretation() == GPI_RGB) c = img.channels() - 1;
// make sure the image band has the same dimensions as the image
if (band->GetXSize() != m_width || band->GetYSize() != m_height){ return cv::Mat(); }
// create a temporary scanline pointer to store data
double* scanline = new double[xWidth];
// iterate over each row and column
for (int y = 0; y<yWidth; y++){
// get the entire row
band->RasterIO(GF_Read, xStart, y + yStart, xWidth, 1, scanline, xWidth, 1, GDT_Float64, 0, 0);
// set inside the image
for (int x = 0; x<xWidth; x++){
// set depending on image types
// given boost, I would use enable_if to speed up. Avoid for now.
if (hasColorTable == false){
write_pixel(scanline[x], gdalType, nChannels, img, y, x, realBandIndex);
}
else{
write_ctable_pixel(scanline[x], gdalType, gdalColorTable, img, y, x, c);
}
}
}
// delete our temp pointer
delete[] scanline;
}
return img;
}
示例4:
/**
* read data
*/
bool KGDAL2CV::readData(cv::Mat img){
// make sure the image is the proper size
if (img.size().height != m_height){
return false;
}
if (img.size().width != m_width){
return false;
}
// make sure the raster is alive
if (m_dataset == NULL || m_driver == NULL){
return false;
}
// set the image to zero
img = 0;
// iterate over each raster band
// note that OpenCV does bgr rather than rgb
int nChannels = m_dataset->GetRasterCount();
GDALColorTable* gdalColorTable = NULL;
if (m_dataset->GetRasterBand(1)->GetColorTable() != NULL){
gdalColorTable = m_dataset->GetRasterBand(1)->GetColorTable();
}
const GDALDataType gdalType = m_dataset->GetRasterBand(1)->GetRasterDataType();
int nRows, nCols;
//if (nChannels > img.channels()){
// nChannels = img.channels();
//}
for (int c = 0; c < img.channels(); c++){
int realBandIndex = c;
// get the GDAL Band
GDALRasterBand* band = m_dataset->GetRasterBand(c + 1);
//if (hasColorTable == false){
if (GCI_RedBand == band->GetColorInterpretation()) realBandIndex = 2;
if (GCI_GreenBand == band->GetColorInterpretation()) realBandIndex = 1;
if (GCI_BlueBand == band->GetColorInterpretation()) realBandIndex = 0;
//}
if (hasColorTable && gdalColorTable->GetPaletteInterpretation() == GPI_RGB) c = img.channels() - 1;
// make sure the image band has the same dimensions as the image
if (band->GetXSize() != m_width || band->GetYSize() != m_height){ return false; }
// grab the raster size
nRows = band->GetYSize();
nCols = band->GetXSize();
// create a temporary scanline pointer to store data
double* scanline = new double[nCols];
// iterate over each row and column
for (int y = 0; y<nRows; y++){
// get the entire row
band->RasterIO(GF_Read, 0, y, nCols, 1, scanline, nCols, 1, GDT_Float64, 0, 0);
// set inside the image
for (int x = 0; x<nCols; x++){
// set depending on image types
// given boost, I would use enable_if to speed up. Avoid for now.
if (hasColorTable == false){
write_pixel(scanline[x], gdalType, nChannels, img, y, x, realBandIndex);
}
else{
write_ctable_pixel(scanline[x], gdalType, gdalColorTable, img, y, x, c);
}
}
}
// delete our temp pointer
delete[] scanline;
}
return true;
}