void RGBFilter::SetInput(ImageType::Pointer InputImage){ this->inputImage = InputImage; // output image allocation this->outputImage = ImageType::New(); ImageType::IndexType outputIndex; outputIndex.Fill(0); RegionType anotherRegion; anotherRegion.SetIndex(outputIndex); anotherRegion.SetSize(this->inputImage->GetLargestPossibleRegion().GetSize()); outputImage->SetLargestPossibleRegion(anotherRegion); outputImage->SetBufferedRegion(anotherRegion); outputImage->SetRequestedRegion(anotherRegion); outputImage->Allocate(); this->ImRed = ChannelType::New(); ChannelType::IndexType outputIndex2; outputIndex2.Fill(0); RegionType anotherRegion2; anotherRegion2.SetIndex(outputIndex2); anotherRegion2.SetSize(this->inputImage->GetLargestPossibleRegion().GetSize()); ImRed->SetLargestPossibleRegion(anotherRegion2); ImRed->SetBufferedRegion(anotherRegion2); ImRed->SetRequestedRegion(anotherRegion2); ImRed->Allocate(); this->ImGreen = ChannelType::New(); ChannelType::IndexType outputIndex3; outputIndex3.Fill(0); RegionType anotherRegion3; anotherRegion3.SetIndex(outputIndex3); anotherRegion3.SetSize(this->inputImage->GetLargestPossibleRegion().GetSize()); ImGreen->SetLargestPossibleRegion(anotherRegion3); ImGreen->SetBufferedRegion(anotherRegion3); ImGreen->SetRequestedRegion(anotherRegion3); ImGreen->Allocate(); this->ImBlue = ChannelType::New(); ChannelType::IndexType outputIndex4; outputIndex4.Fill(0); RegionType anotherRegion4; anotherRegion4.SetIndex(outputIndex4); anotherRegion4.SetSize(this->inputImage->GetLargestPossibleRegion().GetSize()); ImBlue->SetLargestPossibleRegion(anotherRegion4); ImBlue->SetBufferedRegion(anotherRegion4); ImBlue->SetRequestedRegion(anotherRegion4); ImBlue->Allocate(); }
vtkPolyData *mitk::Surface::GetVtkPolyData(unsigned int t) const { if (t < m_PolyDatas.size()) { if (m_PolyDatas[t] == nullptr && this->GetSource().IsNotNull()) { RegionType requestedRegion; requestedRegion.SetIndex(3, t); requestedRegion.SetSize(3, 1); this->m_RequestedRegion = requestedRegion; this->GetSource()->Update(); } return m_PolyDatas[t].GetPointer(); } return nullptr; }
vtkUnstructuredGrid* mitk::UnstructuredGrid::GetVtkUnstructuredGrid(unsigned int t) { if ( t < m_GridSeries.size() ) { vtkUnstructuredGrid* grid = m_GridSeries[ t ]; if((grid == 0) && (GetSource().GetPointer() != 0)) { RegionType requestedregion; requestedregion.SetIndex(3, t); requestedregion.SetSize(3, 1); SetRequestedRegion(&requestedregion); GetSource()->Update(); } grid = m_GridSeries[ t ]; return grid; } else return 0; }
unsigned int MultiThreadedImageIOBase::SplitRequestedRegion (unsigned int id, unsigned int total, RegionType& region) { int fileCount = (int)( m_FileNames.size() ); int threadFileCount = (int)::ceil( fileCount/(double)total ); RegionType::IndexType start; start[0] = id * threadFileCount; RegionType::SizeType length; length[0] = threadFileCount; unsigned int maxThreadInUse = (unsigned int)::ceil(fileCount/(double)threadFileCount) - 1; if( id == maxThreadInUse ) length[0] = fileCount - start[0]; region.SetIndex (start); region.SetSize (length); return maxThreadInUse+1; }
vtkPolyData* mitk::Surface::GetVtkPolyData( unsigned int t ) { if ( t < m_PolyDataSeries.size() ) { vtkPolyData* polydata = m_PolyDataSeries[ t ]; if((polydata==NULL) && (GetSource().GetPointer()!=NULL)) { RegionType requestedregion; requestedregion.SetIndex(3, t); requestedregion.SetSize(3, 1); SetRequestedRegion(&requestedregion); GetSource()->Update(); } polydata = m_PolyDataSeries[ t ]; return polydata; } else return NULL; }
float rich_cell:: compute_average_intensity( ImageType::Pointer intensity_image, LabelImageType::ConstPointer label_image, int dist_interior, int dist_exterior) { float sum_interior = 0; float sum_exterior = 0; int count_interior = 0; int count_exterior = 0; if (dist_exterior < dist_interior) { // the entire segmented area is taken for (unsigned int b = 0; b<all_points_.size(); b++) { vnl_vector_fixed< float, 3 > const & pt = all_points_[b]; ImageType::IndexType pos; pos[0] = pt[0]; pos[1] = pt[1]; pos[2] = pt[2]; sum_interior += intensity_image->GetPixel(pos); } return sum_interior/all_points_.size(); } RegionType region = bounding_box_; if (dist_interior < 0) { //erode the mask // Generate a mask image of the cell region. Erode the region by // r_interior RegionType::SizeType size = region.GetSize(); RegionType::IndexType start={{0,0,0}}; ImageType::Pointer cropped_mask = ImageType::New(); RegionType mask_region; mask_region.SetIndex( start ); mask_region.SetSize( size ); cropped_mask->SetRegions( mask_region ); cropped_mask->Allocate(); cropped_mask->FillBuffer(0); LabelConstRegionIteratorType it1( label_image, region); RegionIteratorType it2( cropped_mask, mask_region ); for (it1.GoToBegin(), it2.GoToBegin(); !it1.IsAtEnd(); ++it1, ++it2) { if (it1.Get() == label_) it2.Set( 255 ); } ImageType::Pointer eroded_mask; ErodeFilterType::Pointer f_erode = ErodeFilterType::New(); SubFilterType::Pointer f_sub = SubFilterType::New(); StructuringElementType structuringElement; structuringElement.SetRadius( -dist_interior ); structuringElement.CreateStructuringElement(); f_erode->SetKernel( structuringElement ); f_erode->SetInput(cropped_mask); f_sub->SetInput1( cropped_mask ); f_sub->SetInput2( f_erode->GetOutput() ); try { f_sub->Update(); } catch (itk::ExceptionObject & e) { std::cerr << "Exception in SubFilter: " << e << std::endl; exit(0); } eroded_mask = f_sub->GetOutput(); // Sum the signal in the eroded region only ConstRegionIteratorType it3( eroded_mask, mask_region ); ConstRegionIteratorType it4( intensity_image, region); for (it3.GoToBegin(), it4.GoToBegin(); !it3.IsAtEnd(); ++it1, ++it3, ++it4) { if (it3.Get() > 0) { sum_interior += it4.Get(); count_interior ++; } } } if (dist_exterior > 0) { //dilate the mask // enlarge the bounding box by r on each side. RegionType::SizeType image_size = intensity_image->GetLargestPossibleRegion().GetSize(); RegionType::SizeType size = region.GetSize(); RegionType::IndexType start = region.GetIndex(); RegionType::IndexType end; end[0] = vnl_math_min(start[0]+size[0]+dist_exterior, image_size[0]); end[1] = vnl_math_min(start[1]+size[1]+dist_exterior, image_size[1]); end[2] = vnl_math_min(start[2]+size[2]+dist_exterior, image_size[2]); start[0] = vnl_math_max(int(start[0]-dist_exterior), 0); start[1] = vnl_math_max(int(start[1]-dist_exterior), 0); start[2] = vnl_math_max(int(start[2]-dist_exterior), 0); size[0] = end[0] - start[0]; size[1] = end[1] - start[1]; size[2] = end[2] - start[2]; region.SetSize( size ); region.SetIndex( start ); // Generate a mask image of the region just found. Dilate the // region defined by the segmentation by r. ImageType::Pointer cropped_mask = ImageType::New(); RegionType mask_region; start[0] = start[1] = start[2] = 0; mask_region.SetIndex( start ); mask_region.SetSize( size ); cropped_mask->SetRegions( mask_region ); cropped_mask->Allocate(); cropped_mask->FillBuffer(0); LabelConstRegionIteratorType it1( label_image, region); RegionIteratorType it2( cropped_mask, mask_region ); for (it1.GoToBegin(), it2.GoToBegin(); !it1.IsAtEnd(); ++it1, ++it2) { if (it1.Get() == label_) it2.Set( 255 ); } ImageType::Pointer dilated_mask; DilateFilterType::Pointer f_dilate = DilateFilterType::New(); SubFilterType::Pointer f_sub = SubFilterType::New(); StructuringElementType structuringElement; structuringElement.SetRadius( dist_exterior ); structuringElement.CreateStructuringElement(); f_dilate->SetKernel( structuringElement ); f_dilate->SetInput(cropped_mask); f_sub->SetInput1( f_dilate->GetOutput() ); f_sub->SetInput2( cropped_mask ); try { f_sub->Update(); } catch (itk::ExceptionObject & e) { std::cerr << "Exception in SubFilter: " << e << std::endl; exit(0); } dilated_mask = f_sub->GetOutput(); // Sum the signal in the dilated region only ConstRegionIteratorType it3( dilated_mask, mask_region ); ConstRegionIteratorType it4( intensity_image, region); for (it3.GoToBegin(), it4.GoToBegin(); !it3.IsAtEnd(); ++it1, ++it3, ++it4) { if (it3.Get() > 0) { sum_exterior += it4.Get(); count_exterior ++; } } } // average the interior and exterior signals return (sum_interior+sum_exterior)/float(count_interior+count_exterior); }