I am trying to copy the vtkImageData * class to the cv :: Mat structure [my goal is to read the MHD file in OpenCV]. The file is essentially a 3D matrix, so I want to get a vector containing all the pieces of volume. So far I have come up with this code,
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);
extractVOI->GetOutput()->SetScalarTypeToSignedChar();
imageExport->SetInputConnection(extractVOI->GetOutputPort());
imageExport->Update();
cv::Mat cvMat_test(dims[0], dims[1], CV_8UC1, imageExport->GetPointerToData());
Although this works, it does not give me the expected result (which is highlighted below). Any help on this would be very helpful.
Thanks in advance, Sarthak
Expected Result,

The output I get right now

EDIT: I understand that the images are not the same size. This is because I just posted a snapshot of the data from the viewer that I am using. The following link gives an example: HERE . Hope this clarifies the situation a bit more.
TAGS: vtk opencv bridge, vtkopencv, vtk opencv