suppose that I have a

vector<unsigned char>a  

which is the raster information of a geotiff image extracted by the RasterIO function of the GDAL library( an opensource library for geographic information systems)
my image is a 7697x7309 one so the vector has 56257373 members.
How can I apply a 5x5 gaussian filter on this vector and then gain the result as another 56257373 members vector of the type unsigned char to be able to save the vector as another geotiff image using GDAL library.


My main question is the above but if it's not possible tell me if I have a geotiff file how can I apply filters on it using opencv at run-time. I mean I don't want to convert the format to another one like bitmap and tiff on the hard and then read data from hard to apply processes on that, suppose that I have data in GDAL format in one part of the memory and want to convert it to opencv compatible data in another part and apply filters on it?

有帮助吗?

解决方案

I think this is what you are asking for:

// 1. Convert vector to Mat

cv::Mat amat(7309, 7697, CV_8UC1, &a[0]);

// 2. Apply 5x5 Gaussian filter

cv::Mat bmat;  // blurred output, sigma=1.4 assumed below
cv::GaussianBlur(amat, bmat, cv::Size(5,5), 1.4); 

// 3. Convert Mat to vector

cv::Mat cmat = bmat.reshape(1, 1); // make the Mat one big long row
std::vector<unsigned char>b = cmat;

其他提示

A simpler than the vector< > way to convert from GDAL to OpenCV raster data:

//Region of Interest to be read
cv::Rect roi(x, y, w, h);

//Mat allocation to store the data
cv::Mat mat;
mat.create(roi.size(),CV_32F);

//data is stored directly in the mat passing the mat.data pointer to RasterIO
band->RasterIO( GF_Read, roi.x, roi.y, roi.width, roi.height, mat.data,
                roi.width, roi.height, GDT_Float32, 0, 0);

You just have to be sure that OpenCV datatype fit the GDAL datatype and that ROI dimensions are ok for the raster size

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top