# The collapse of the dimension using extractFilter does not make sense

**URL:** https://discourse.itk.org/t/the-collapse-of-the-dimension-using-extractfilter-does-not-make-sense/1642
**Category:** Uncategorized
**Created:** [March 8, 2019, 9:50am UTC](https://discourse.itk.org/t/the-collapse-of-the-dimension-using-extractfilter-does-not-make-sense/1642 "2019-03-08T09:50:08Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![zandarina](https://discourse.itk.org/letter_avatar_proxy/v4/letter/z/4af34b/32.png) [@zandarina](https://discourse.itk.org/u/zandarina)
#### Post date: [March 8, 2019, 9:50am UTC](https://discourse.itk.org/t/the-collapse-of-the-dimension-using-extractfilter-does-not-make-sense/1642/1 "2019-03-08T09:50:08Z")

</div>

Dear all,

I want to do 3d segmentation of an especific vessel but i am having a lot of problems with memory with the 3d filters as this vessels has no contrast at all and i do not have any prior info only intensities and I have decided to do it in 2d. I read a series of dicoms and I am trying to collapse the x dimension because it is the view where i can see much better the vessel. I check the dimensions and they are correct [numberslice,589,180] and i copy the result in a 2d dicom and I see that the result doesn´t show what it is expect. It is as if the image was twisted when it reads the series and then when i read the matrix (volume) through x, the results does not have anything to do with the view i want to see.

Any help?. Thanks

```
// Find input image size
	InputImageType::RegionType inputRegion =
	reader->GetOutput()->GetLargestPossibleRegion();
	InputImageType::SizeType size = inputRegion.GetSize();
	const unsigned int collapseDim = 0;
	InputImageType::SizeType::SizeValueType numSlices = size[collapseDim];
	size[collapseDim] = 0; // collapse dimension ( 3D->2D )

							 // Set region for 2D extraction
	InputImageType::IndexType start = inputRegion.GetIndex();
	InputImageType::RegionType desiredRegion;
	desiredRegion.SetSize(size);

// Extract 2D slices, perform processing
	for (unsigned int sliceNumber = 0; sliceNumber<numSlices; sliceNumber++)
	{
		start[collapseDim] = sliceNumber;
		desiredRegion.SetIndex(start);

		extractFilter->SetExtractionRegion(desiredRegion);

		
		using PixelType = short;
		constexpr unsigned int Dimension = 2;
		using ImageType = itk::Image< PixelType, Dimension >;

		using WriterType = itk::ImageFileWriter< ImageType >;

		WriterType::Pointer writer = WriterType::New();

		std::string index = std::to_string(sliceNumber);
		std::string fileoutput = "results" + index + ".dcm";

		writer->SetFileName(fileoutput);
		writer->SetInput(extractFilter->GetOutput());

		try
		{
			writer->Update();
		}
		catch (itk::ExceptionObject & err)
		{
			std::cerr << "ExceptionObject caught !" << std::endl;
			std::cerr << err << std::endl;
			return EXIT_FAILURE;
		}

		

	
	}
```

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [March 8, 2019, 3:37pm UTC](https://discourse.itk.org/t/the-collapse-of-the-dimension-using-extractfilter-does-not-make-sense/1642/2 "2019-03-08T15:37:26Z")

</div>

The question is not entirely clear to me. Can you provide some images/screenshots?

---

<div class="post-metadata">

### Author: ![phcerdan](https://discourse.itk.org/user_avatar/discourse.itk.org/phcerdan/32/286_2.png) [@phcerdan](https://discourse.itk.org/u/phcerdan)
#### Post date: [March 8, 2019, 6:41pm UTC](https://discourse.itk.org/t/the-collapse-of-the-dimension-using-extractfilter-does-not-make-sense/1642/3 "2019-03-08T18:41:24Z")

</div>

Not tested but:

```auto
size[collapseDim] = 0; 

```

Try with `1`:

```auto
size[collapseDim] = 1; 

```

And let us know!

---

<div class="post-metadata">

### Author: ![zandarina](https://discourse.itk.org/letter_avatar_proxy/v4/letter/z/4af34b/32.png) [@zandarina](https://discourse.itk.org/u/zandarina)
#### Post date: [March 9, 2019, 7:37pm UTC](https://discourse.itk.org/t/the-collapse-of-the-dimension-using-extractfilter-does-not-make-sense/1642/4 "2019-03-09T19:37:56Z")

</div>

Hello, i think the collapseDim is correct because i want the sagital view but it is the result what i find weird. I realized that the slice was upside down because i created a dicom for each slice to see the result, and it is not

the same as the sagittal view of the 3d slicer when i load the dicom series and it is there where i can see much better the vessels. And the slices i extract are upside down.

Thank you
