# GPU version Demons: the size of output is different from that of input image

**URL:** https://discourse.itk.org/t/gpu-version-demons-the-size-of-output-is-different-from-that-of-input-image/2743
**Category:** Beginner Questions
**Created:** [February 19, 2020, 2:17pm UTC](https://discourse.itk.org/t/gpu-version-demons-the-size-of-output-is-different-from-that-of-input-image/2743 "2020-02-19T14:17:15Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![zhang-qiang-github](https://discourse.itk.org/user_avatar/discourse.itk.org/zhang-qiang-github/32/1183_2.png) [@zhang-qiang-github](https://discourse.itk.org/u/zhang-qiang-github)
#### Post date: [February 19, 2020, 2:17pm UTC](https://discourse.itk.org/t/gpu-version-demons-the-size-of-output-is-different-from-that-of-input-image/2743/1 "2020-02-19T14:17:16Z")

</div>

I am using GPU Demons for myself project. I find a strange bug: the size of input (fix and moving image) is (174, 256, 256), but the size of output is (87, 128, 128).

The main code is:

```
	RegistrationFilterType::Pointer DemonsFilter = RegistrationFilterType::New();
	CommandIterationUpdate::Pointer observer = CommandIterationUpdate::New();
	DemonsFilter->AddObserver(itk::IterationEvent(), observer);
	DemonsFilter->SetFixedImage(fixImageCPUToGPUFilter->GetOutput());
	DemonsFilter->SetMovingImage(movingImageCPUToGPUFilter->GetOutput());
	DemonsFilter->GetOutput()->SetRequestedRegionToLargestPossibleRegion();
	auto sizexxx = gpuDisplacementField->GetLargestPossibleRegion().GetSize();
	if (i != 0)
	{
		DemonsFilter->SetInitialDisplacementField(gpuDisplacementField);
	}
	else
	{
		DemonsFilter->SetInitialDisplacementField(nullptr);
	}

	DemonsFilter->SetNumberOfIterations(nIterations[i]);
	DemonsFilter->SetStandardDeviations(1.0);
	DemonsFilter->Update();
	auto fixImageSize = DemonsFilter->GetFixedImage()->GetLargestPossibleRegion().GetSize();
	std::cout << "fix image size: " << fixImageSize << std::endl;
	auto movingImageSize = DemonsFilter->GetMovingImage()->GetLargestPossibleRegion().GetSize();
	std::cout << "moving image size: " << movingImageSize << std::endl;
	auto displacementSize = DemonsFilter->GetOutput()->GetLargestPossibleRegion().GetSize();
	std::cout << "displacement size: " << displacementSize << std::endl;

```

And the information in the console is:

> fix image size: [174, 256, 256]  
> moving image size: [174, 256, 256]  
> displacement size: [87, 128, 128]

Why the size of displacement is not (174, 256, 256) ??  
Moreover, I have visualized the displacement field, and the result is just random noise. Also, I have checked the input fix and moving image, and they are correct.  
How can I make the demons registration correct?

---

<div class="post-metadata">

### Author: ![zhang-qiang-github](https://discourse.itk.org/user_avatar/discourse.itk.org/zhang-qiang-github/32/1183_2.png) [@zhang-qiang-github](https://discourse.itk.org/u/zhang-qiang-github)
#### Post date: [February 20, 2020, 1:53am UTC](https://discourse.itk.org/t/gpu-version-demons-the-size-of-output-is-different-from-that-of-input-image/2743/2 "2020-02-20T01:53:10Z")

</div>

I have find the bug.

after I set the initial displacement field by:

```auto
DemonsFilter->SetInitialDisplacementField(gpuDisplacementField);

```

I obtian the size of initial displacement by:

```auto
DemonsFilter->GetInitialDisplacementField()->GetLargestPossibleRegion().GetSize();

```

and I find the result is (174, 256, 256)  
actually, the initial displacement field is obtained by:

```auto
	cpuToGpuDisplacementFieldFilter->SetInput(cpuDisplacementField);
	cpuToGpuDisplacementFieldFilter->Update();
	gpuDisplacementField = cpuToGpuDisplacementFieldFilter->GetOutput();

```

If I change:

```auto
cpuToGpuDisplacementFieldFilter->Update();

```

to

```auto
cpuToGpuDisplacementFieldFilter->UpdateLargestPossibleRegion();

```

the result will be correct.  
Also, it really make me confuzed what’s the difference between Update and UpdateLargestPossibleRegion.
