Okay, so the GetPointerToData()
function or GetScalarPointer()
function used directly on the vtkImageData
class are not appropriate for allocation (at least not in a way I could figure out).. So, I devised another method,
reader->SetFileName(INPUT_DATA_1.c_str());
reader->Update();
imageData_1 = reader->GetOutput();
extractVOI->SetInput(imageData_1);
int dims[3];
imageData_1->GetDimensions(dims);
extractVOI->SetVOI(0, dims[0], 0, dims[1], 75, 75); // Set it to z=75
extractVOI->GetOutput()->SetScalarTypeToSignedChar();
cv::Mat cvMat_test(dims[0], dims[1], CV_8UC1);
for (int i=0; i<dims[0]; ++i) {
for (int j=0; j<dims[1]; ++j) {
cvMat_test.at<unsigned char>(cv::Point(j,i)) = *static_cast<unsigned char*>(extractVOI->GetOutput()->GetScalarPointer(i,j,vol_dim));
}
}
I am guessing this method can be extended to include the entire volume pretty easily..
EDIT:
I extended my code to do conversions to and from vtkImageData and cv::Mat and/or cv::gpu::Mat.. I have uploaded to the code here as vtkOpenCVBridge.
Cheers.!