# How to compute & plot hostogram of dicom images?

**URL:** <https://discourse.itk.org/t/how-to-compute-plot-hostogram-of-dicom-images/2822>\
**Category:** Uncategorized\
**Created:** [March 12, 2020, 9:18am UTC](https://discourse.itk.org/t/how-to-compute-plot-hostogram-of-dicom-images/2822 "2020-03-12T09:18:42Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pooja\_Virkar](https://discourse.itk.org/user_avatar/discourse.itk.org/pooja_virkar/32/804_2.png) [@Pooja\_Virkar](https://discourse.itk.org/u/Pooja_Virkar)\
**Post date:** [March 12, 2020, 9:18am UTC](https://discourse.itk.org/t/how-to-compute-plot-hostogram-of-dicom-images/2822/1 "2020-03-12T09:18:42Z")

</div>

Hello,

I want to compute the histogram of dicom images and then plot that graph.

I tried to use the example from  
[https://itk.org/Doxygen/html/SphinxExamples\_2src\_2Numerics\_2Statistics\_2ComputeHistogramFromGrayscaleImage\_2Code\_8cxx-example.html](https://itk.org/Doxygen/html/SphinxExamples_2src_2Numerics_2Statistics_2ComputeHistogramFromGrayscaleImage_2Code_8cxx-example.html)

It gives me frequency values with number of bins of 256.  
How to select number of bins for dicom image?

And how to plot it in graph? And then how to calculate thresholds from histogram, which I can use it later in Connected threshold image filter? Is it correct way to do segmentation?

Please help me.  
Thanks in advance.

---

<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 12, 2020, 1:39pm UTC](https://discourse.itk.org/t/how-to-compute-plot-hostogram-of-dicom-images/2822/2 "2020-03-12T13:39:00Z")

</div>

> [@Pooja\_Virkar](#):
>
> Is it correct way to do segmentation?

That is one way to do segmentation. Depending on your problem, it might or might not work. If you can’t tell in advance, you can try it and know for sure.

ITK does not do plotting. [VTK can do it](https://vtk.org/Wiki/VTK/Examples/Cxx/Plotting/LinePlot). Excel and LibreOffice Calc can do it if you write it into a CSV file.

---

<div class="post-metadata">

**Author:** ![Pooja\_Virkar](https://discourse.itk.org/user_avatar/discourse.itk.org/pooja_virkar/32/804_2.png) [@Pooja\_Virkar](https://discourse.itk.org/u/Pooja_Virkar)\
**Post date:** [March 12, 2020, 2:02pm UTC](https://discourse.itk.org/t/how-to-compute-plot-hostogram-of-dicom-images/2822/3 "2020-03-12T14:02:41Z")

</div>

Thanks for your reply.

I am trying to segment blood vessels of liver. And I want to use connected thresholding and for that I need thresholds.

I was thinking to take histogram and then from that I can calculate thresholds.  
Because I don’t know how to select threshold values in filter. Is it same like CT value(HU value)?

Could you please tell me, will this work and/or any different way to achieve it? And is there any other way to calculate & plot histogram in VTK?  
And how can I compute histogram of dicom series?

Please help me.

---

<div class="post-metadata">

**Author:** ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)\
**Post date:** [March 12, 2020, 2:08pm UTC](https://discourse.itk.org/t/how-to-compute-plot-hostogram-of-dicom-images/2822/4 "2020-03-12T14:08:33Z")

</div>

Hello @Pooja_Virkar,

[itkwidgets](https://github.com/InsightSoftwareConsortium/itkwidgets) may be of interest. Every image visualization includes an interactive histogram, which makes it extremely easy to understand threshold values, etc.

To read and view a DICOM series, e.g.

```auto
import itk
from glob import glob
from itkwidgets import view

series = glob('dicom_series_folder/*.dcm')
series.sort()
image = itk.imread(series)
view(image)

```

---

<div class="post-metadata">

**Author:** ![Pooja\_Virkar](https://discourse.itk.org/user_avatar/discourse.itk.org/pooja_virkar/32/804_2.png) [@Pooja\_Virkar](https://discourse.itk.org/u/Pooja_Virkar)\
**Post date:** [March 13, 2020, 9:07am UTC](https://discourse.itk.org/t/how-to-compute-plot-hostogram-of-dicom-images/2822/5 "2020-03-13T09:07:40Z")

</div>

Hello,

The solution you provided i.e. itkwidgets is with python.

But I am using ITK and VTK in c++.  
So Is there any other way to get histogram of complete dicom series using ITK or VTK in C++? And then use it to select thresholds?

---

<div class="post-metadata">

**Author:** ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)\
**Post date:** [March 13, 2020, 1:37pm UTC](https://discourse.itk.org/t/how-to-compute-plot-hostogram-of-dicom-images/2822/6 "2020-03-13T13:37:19Z")

</div>

ITK has around a dozen of filters that will automatically select a threshold based on the image’s intensity histogram:

[https://itk.org/Doxygen/html/group\_\_ITKThresholding.html](https://itk.org/Doxygen/html/group__ITKThresholding.html)
