# How to set pre-defined points in the fixed image in gui?

**URL:** https://discourse.itk.org/t/how-to-set-pre-defined-points-in-the-fixed-image-in-gui/5519
**Category:** Beginner Questions
**Tags:** registration, python, simpleitk
**Created:** [November 23, 2022, 6:40am UTC](https://discourse.itk.org/t/how-to-set-pre-defined-points-in-the-fixed-image-in-gui/5519 "2022-11-23T06:40:33Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![debapriya](https://discourse.itk.org/letter_avatar_proxy/v4/letter/d/bc79bd/32.png) [@debapriya](https://discourse.itk.org/u/debapriya)
#### Post date: [November 23, 2022, 6:40am UTC](https://discourse.itk.org/t/how-to-set-pre-defined-points-in-the-fixed-image-in-gui/5519/1 "2022-11-23T06:40:33Z")

</div>

Hello,  
I have a list of pre-defined co-ordinates written in a text file.

 ![Co-ordinates](https://discourse.itk.org/uploads/default/original/2X/2/297e8bdd16e9edda5ec2fa2550d8aca522012e3d.jpeg)

I want to mark these co-ordinates in the fixed image in the gui. After the marked fixed image is obtained, the corresponding co-ordinates in the moving image will be marked manually. The resulting fixed-moving co-ordinate pairs will be used for landmark based registration.

The codes available in SimpleITK require fixed and moving images to be marked simultaneously. Is it possible to mark a set of points in the fixed image first, then find out the corresponding points in the moving image manually?

---

<div class="post-metadata">

### Author: ![zivy](https://discourse.itk.org/user_avatar/discourse.itk.org/zivy/32/1726_2.png) [@zivy](https://discourse.itk.org/u/zivy)
#### Post date: [November 23, 2022, 4:59pm UTC](https://discourse.itk.org/t/how-to-set-pre-defined-points-in-the-fixed-image-in-gui/5519/2 "2022-11-23T16:59:46Z")

</div>

Hello @debapriya,

Unfortunately, the functionality you are asking for is not supported by the `RegistrationPointDataAquisition` component. Currently it only [adds points via user clicks](https://github.com/InsightSoftwareConsortium/SimpleITK-Notebooks/blob/19c67e5441511515573577ad6005ffd94e7551dd/Python/gui.py#L292-L359) and enforces that these be pairs (can’t add multiple points to moving/fixed, have to alternate between them and this establishes the pairing).

You will need to modify the [code](https://github.com/InsightSoftwareConsortium/SimpleITK-Notebooks/blob/master/Python/gui.py) to add the functionality you want.

---

<div class="post-metadata">

### Author: ![debapriya](https://discourse.itk.org/letter_avatar_proxy/v4/letter/d/bc79bd/32.png) [@debapriya](https://discourse.itk.org/u/debapriya)
#### Post date: [November 26, 2022, 2:00pm UTC](https://discourse.itk.org/t/how-to-set-pre-defined-points-in-the-fixed-image-in-gui/5519/3 "2022-11-26T14:00:12Z")

</div>

Ok. I’ll try and make the necessary changes in `gui.py`.

My goal is that I want more than one expert to mark points on the moving image, corresponding to a list of fixed image co-ordinates given in a text file. The final set of moving coordinates will be the mean of the points marked by the experts.

---

<div class="post-metadata">

### Author: ![debapriya](https://discourse.itk.org/letter_avatar_proxy/v4/letter/d/bc79bd/32.png) [@debapriya](https://discourse.itk.org/u/debapriya)
#### Post date: [November 30, 2022, 7:48am UTC](https://discourse.itk.org/t/how-to-set-pre-defined-points-in-the-fixed-image-in-gui/5519/4 "2022-11-30T07:48:49Z")

</div>

I have added a `print("Hello World")` command at the beginning of ` __call__ ` in `gui.py`, to check if ` __call__ ` is invoked when we click inside the figure.

No `Hello World` is showing on clicking inside the figure. However, the rest of the function is working properly, indicating ` __call__ ` is invoked. What could be the reason?

---

<div class="post-metadata">

### Author: ![zivy](https://discourse.itk.org/user_avatar/discourse.itk.org/zivy/32/1726_2.png) [@zivy](https://discourse.itk.org/u/zivy)
#### Post date: [November 30, 2022, 2:49pm UTC](https://discourse.itk.org/t/how-to-set-pre-defined-points-in-the-fixed-image-in-gui/5519/5 "2022-11-30T14:49:36Z")

</div>

Hello @debapriya,

The GUI is overlaying onto the cell output so the prints are not going to be visible. Simply write to file in the ` __call__ `:

```auto
with open("gui_log.txt", "a") as fp:
  print("hello", file=fp)

```

---

<div class="post-metadata">

### Author: ![debapriya](https://discourse.itk.org/letter_avatar_proxy/v4/letter/d/bc79bd/32.png) [@debapriya](https://discourse.itk.org/u/debapriya)
#### Post date: [December 2, 2022, 6:53am UTC](https://discourse.itk.org/t/how-to-set-pre-defined-points-in-the-fixed-image-in-gui/5519/6 "2022-12-02T06:53:32Z")

</div>

It worked. Thank you.

Now, I am trying to set a counter, which will increase by 1, every time user clicks on the fixed image. I have written the following code for this purpose.

```auto
if self.viewing_checkbox.value == "edit":            
   if event.inaxes == self.fixed_axes:
       self.countF = self.countF + 1
       with open("gui_logF.txt", "w") as fp:
               print("Hello", file=fp)

```

`gui_logF.txt` is not created in this case. However, when I remove `self.countF = self.countF + 1`, the code snippet is working, and `gui_logF.txt` is created.

What is the reason?  
Also, please share some study links on this topic, if possible.
