| 184 | */ |
| 185 | template<typename TMatrixElementType> |
| 186 | static mitk::Image::Pointer Transform(const Eigen::Matrix<TMatrixElementType, Eigen::Dynamic, Eigen::Dynamic> & matrix, const mitk::Image::Pointer & mask) |
| 187 | { |
| 188 | itk::Image<unsigned int, 3>::Pointer itkMask; |
| 189 | mitk::CastToItkImage(mask,itkMask); |
| 190 | |
| 191 | typename itk::Image<TMatrixElementType, 3>::Pointer itk_img = itk::Image<TMatrixElementType, 3>::New(); |
| 192 | itk_img->SetRegions(itkMask->GetLargestPossibleRegion()); |
| 193 | itk_img->SetOrigin(itkMask->GetOrigin()); |
| 194 | itk_img->SetSpacing(itkMask->GetSpacing()); |
| 195 | itk_img->SetDirection(itkMask->GetDirection()); |
| 196 | itk_img->Allocate(); |
| 197 | |
| 198 | |
| 199 | unsigned int n_numSamples = 0; |
| 200 | mitk::CLUtil::CountVoxel(mask,n_numSamples); |
| 201 | |
| 202 | if(n_numSamples != matrix.rows()) |
| 203 | MITK_ERROR << "Number of samples in matrix and number of points under the masks is not the same!"; |
| 204 | |
| 205 | auto mit = itk::ImageRegionConstIterator<itk::Image<unsigned int, 3> >(itkMask, itkMask->GetLargestPossibleRegion()); |
| 206 | auto oit = itk::ImageRegionIterator<itk::Image<TMatrixElementType, 3> >(itk_img, itk_img->GetLargestPossibleRegion()); |
| 207 | |
| 208 | unsigned int current_row = 0; |
| 209 | while(!mit.IsAtEnd()) |
| 210 | { |
| 211 | if(mit.Value() > 0) |
| 212 | oit.Set(matrix(current_row++,0)); |
| 213 | else |
| 214 | oit.Set(0.0); |
| 215 | ++mit; |
| 216 | ++oit; |
| 217 | } |
| 218 | |
| 219 | mitk::Image::Pointer out_img = mitk::Image::New(); |
| 220 | mitk::GrabItkImageMemory(itk_img,out_img); |
| 221 | return out_img; |
| 222 | } |
| 223 | /** |
| 224 | * \brief Transform an MITK image into an Eigen column matrix using a mask. |
| 225 | * |
nothing calls this directly
no test coverage detected