# Metal artifact reduction (MAR) of CT development

**URL:** <https://discourse.slicer.org/t/metal-artifact-reduction-mar-of-ct-development/16200>\
**Category:** Support\
**Tags:** build, dicom, python\
**Created:** [February 25, 2021, 3:46am UTC](https://discourse.slicer.org/t/metal-artifact-reduction-mar-of-ct-development/16200 "2021-02-25T03:46:32Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![full\_stack\_master](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/full_stack_master/32/9693_2.png) [@full\_stack\_master](https://discourse.slicer.org/u/full_stack_master)\
**Post date:** [February 25, 2021, 3:46am UTC](https://discourse.slicer.org/t/metal-artifact-reduction-mar-of-ct-development/16200/1 "2021-02-25T03:46:32Z")

</div>

I want to get the function of MAR  
I have developed the MAR function in my end but it takes much time (30 mins)  
I have used the 400 DICOM files for testing  
I want to reduce running time from 30mins to 1 min  
this is the code for 1 dicom file  
it takes 25s to complete 1 file

```python
def calc_mar1(self, shapes, image1):
    image = apply_voi_lut(image1, self.ds)
    tmp_image = image
    m = max(abs(np.min(image)),np.max(image))
    image = image + m
    omax = np.max(image)
    image = image / omax
    theta = np.linspace(0., 180., shapes[0], endpoint=False)
    sinogram = skimage.transform.radon(image, theta=theta, circle=True)
    if self.marthreshold > 0 :
      eff = self.marthreshold
    else:
      eff = 0.65
    th = 190 * eff
    sinogram[sinogram > th] = th
    reconstruction_fbp = skimage.transform.iradon(sinogram, theta=theta, circle=True)
    tmp_image[tmp_image < tmp_image * 0.995] = 0
    scaled_img = self.ds.WindowWidth * reconstruction_fbp - self.ds.WindowCenter 
    scaled_img = scaled_img + (tmp_image / (np.max(tmp_image))) * self.ds.WindowWidth
    self.tmpArray1.append(scaled_img)

```

---

<div class="post-metadata">

**Author:** ![full\_stack\_master](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/full_stack_master/32/9693_2.png) [@full\_stack\_master](https://discourse.slicer.org/u/full_stack_master)\
**Post date:** [February 25, 2021, 4:12am UTC](https://discourse.slicer.org/t/metal-artifact-reduction-mar-of-ct-development/16200/2 "2021-02-25T04:12:44Z")

</div>

I have the code for MAR using DICOM files  
But it takes much time (25s for 1 file , 30 mins for 400 files)  
So I want you to reduce running time from 30mins to 1 min

```python
def calc_mar1(self, shapes, image1):

   image = apply_voi_lut(image1, self.ds)
   print(image)
   tmp_image = image
   m = max(abs(np.min(image)),np.max(image))
   image = image + m
   omax = np.max(image)
   image = image / omax
   theta = np.linspace(0., 180., shapes[0], endpoint=False)
   sinogram = skimage.transform.radon(image, theta=theta, circle=True)
   # print("Sinogram:===>")
   # print(np.max(sinogram))
   if self.marthreshold > 0 :
     eff = self.marthreshold
   else:
     eff = 0.65
   th = 190 * eff
   sinogram[sinogram > th] = th
   reconstruction_fbp = skimage.transform.iradon(sinogram, theta=theta, circle=True)
   # delta = np.pi / shapes[0]
   # reconstruction_fbp = RLIRadonTransform(shapes[0], shapes[0] + 1, sinogram, delta)
   tmp_image[tmp_image < tmp_image * 0.995] = 0
   # print(window_width)
   scaled_img = self.ds.WindowWidth * reconstruction_fbp - self.ds.WindowCenter 
   print("tmp_image")
   print(np.max(tmp_image))
   print(np.max(scaled_img))
   scaled_img = scaled_img + (tmp_image / (np.max(tmp_image))) * self.ds.WindowWidth
   self.tmpArray1.append(scaled_img) 
   # print(self.tmpArray[index1])
   return

```

---

<div class="post-metadata">

**Author:** ![full\_stack\_master](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/full_stack_master/32/9693_2.png) [@full\_stack\_master](https://discourse.slicer.org/u/full_stack_master)\
**Post date:** [February 25, 2021, 4:14am UTC](https://discourse.slicer.org/t/metal-artifact-reduction-mar-of-ct-development/16200/3 "2021-02-25T04:14:18Z")

</div>

```python
def calc_mar1(self, shapes, image1):

    image = apply_voi_lut(image1, self.ds)
    print(image)
    tmp_image = image
    m = max(abs(np.min(image)),np.max(image))
    image = image + m
    omax = np.max(image)
    image = image / omax
    theta = np.linspace(0., 180., shapes[0], endpoint=False)
    sinogram = skimage.transform.radon(image, theta=theta, circle=True)
    # print("Sinogram:===>")
    # print(np.max(sinogram))
    if self.marthreshold > 0 :
      eff = self.marthreshold
    else:
      eff = 0.65
    th = 190 * eff
    sinogram[sinogram > th] = th
    reconstruction_fbp = skimage.transform.iradon(sinogram, theta=theta, circle=True)
    # delta = np.pi / shapes[0]
    # reconstruction_fbp = RLIRadonTransform(shapes[0], shapes[0] + 1, sinogram, delta)
    tmp_image[tmp_image < tmp_image * 0.995] = 0
    # print(window_width)
    scaled_img = self.ds.WindowWidth * reconstruction_fbp - self.ds.WindowCenter 
    print("tmp_image")
    print(np.max(tmp_image))
    print(np.max(scaled_img))
    scaled_img = scaled_img + (tmp_image / (np.max(tmp_image))) * self.ds.WindowWidth
    self.tmpArray1.append(scaled_img) 
    # print(self.tmpArray[index1])
    return

```

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [February 25, 2021, 6:11am UTC](https://discourse.slicer.org/t/metal-artifact-reduction-mar-of-ct-development/16200/4 "2021-02-25T06:11:33Z")

</div>

Probably it would be hard to improve the performance of radon/iradon CPU implementation in scikit-image. I would suggest to try a GPU implementation, such as [this one](http://christian.mendl.net/software/radon_gpu_manuscript.pdf) (it seems that they provide source code, but I did not check what they provide exactly).

---

<div class="post-metadata">

**Author:** ![full\_stack\_master](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/full_stack_master/32/9693_2.png) [@full\_stack\_master](https://discourse.slicer.org/u/full_stack_master)\
**Post date:** [February 25, 2021, 7:34am UTC](https://discourse.slicer.org/t/metal-artifact-reduction-mar-of-ct-development/16200/5 "2021-02-25T07:34:15Z")

</div>

thanks for your great efforts  
I am sorry but how can we get the solution for MAR in 3d slicer?  
I can not see anything for this function now

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [February 25, 2021, 1:18pm UTC](https://discourse.slicer.org/t/metal-artifact-reduction-mar-of-ct-development/16200/6 "2021-02-25T13:18:46Z")

</div>

You can run the code snippets above in Slicer’s Python console or you can put them in a Python scripted module.

If you want a GPU-accelerated radon transform then check if you can find such a Python package. If there isn’t any then you can use any C++ implementations of the radon transform that you find, by building Slicer and a C++ loadable module.
