# jpg2000

**URL:** https://discourse.itk.org/t/jpg2000/1345
**Category:** Beginner Questions
**Created:** [October 11, 2018, 9:18am UTC](https://discourse.itk.org/t/jpg2000/1345 "2018-10-11T09:18:40Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![ludicludo](https://discourse.itk.org/user_avatar/discourse.itk.org/ludicludo/32/526_2.png) [@ludicludo](https://discourse.itk.org/u/ludicludo)
#### Post date: [October 11, 2018, 9:18am UTC](https://discourse.itk.org/t/jpg2000/1345/1 "2018-10-11T09:18:40Z")

</div>

Hi everyone,  
I would like to process histological images with simpleITK or ITK saved as jpg2000 format.  
It seems that simpleITK doesn’t handle this format. Is it possible to register this specific format in simpleITK or ITK ?  
Best regards  
Ludovic

---

<div class="post-metadata">

### Author: ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)
#### Post date: [October 11, 2018, 11:16am UTC](https://discourse.itk.org/t/jpg2000/1345/2 "2018-10-11T11:16:46Z")

</div>

Do you have a sample image? What file extensions do your files have?

---

<div class="post-metadata">

### Author: ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)
#### Post date: [October 11, 2018, 4:01pm UTC](https://discourse.itk.org/t/jpg2000/1345/3 "2018-10-11T16:01:00Z")

</div>

This patch here in review:  
[http://review.source.kitware.com/#/c/23803/2](http://review.source.kitware.com/#/c/23803/2)

This should make the JPEG2000 ImageIO behave like a normal IO module. When this patch gets merged, SimpleITK can be compiled with the " Module\_ITKIOJPEG2000:BOOL=ON" enabled to get support for JPEG2000.

---

<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: [October 11, 2018, 4:46pm UTC](https://discourse.itk.org/t/jpg2000/1345/4 "2018-10-11T16:46:01Z")

</div>

Without this patch, JPEG2000 support is in `Review` module. To get it, turn on `Module_ITKReview` in CMake configuration and rebuild ITK.

---

<div class="post-metadata">

### Author: ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)
#### Post date: [October 11, 2018, 5:01pm UTC](https://discourse.itk.org/t/jpg2000/1345/5 "2018-10-11T17:01:50Z")

</div>

> [@dzenanz](#):
>
> Without this patch, JPEG2000 support is in `Review` module. To get it, turn on `Module_ITKReview` in CMake configuration and rebuild ITK.

This enables the support, but then the factory needs to be manually registered via “itk::JPEG2000ImageIOFactory::JPEG2000ImageIOFactory()” or explicitly set to the reader via “itk::ImageFileReader::SetImageIO” with a constructed JPEG2000ImageIO object.

---

<div class="post-metadata">

### Author: ![ludicludo](https://discourse.itk.org/user_avatar/discourse.itk.org/ludicludo/32/526_2.png) [@ludicludo](https://discourse.itk.org/u/ludicludo)
#### Post date: [October 11, 2018, 7:31pm UTC](https://discourse.itk.org/t/jpg2000/1345/6 "2018-10-11T19:31:52Z")

</div>

Thank you for your reply.  
Ok for patching and rebuilding ITK.

- Would SimpleITK be affected by this patch once a proper rebuild has been performed ?
- Would it be possible to load a huge image file by smaller patches without RAM overload ?  
Regards  
Ludovic

---

<div class="post-metadata">

### Author: ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)
#### Post date: [October 11, 2018, 7:59pm UTC](https://discourse.itk.org/t/jpg2000/1345/7 "2018-10-11T19:59:13Z")

</div>

After the patch is merged into ITK master you can compile the current development SimpleITK from git with ITKv5 and JPEG2000 support with the following configuration command:

```auto
cmake
   -DModule_ITKIOJPEG2000:BOOL=ON
   -DCMAKE_CXX_STANDARD:STRING=11
   -DITK_GIT_TAG:STRING=master
   -DITKV4_COMPATIBILITY:BOOL=ON
   -DITK_LEGACY_REMOVE:BOOL=OFF
   SimpleITK/SuperBuild

```

Also in the development version of SimpleITK is support for IO Streaming. This adds [sitk::ImageFileReader::SetExtractIndex](https://itk.org/SimpleITKDoxygen/html/classitk_1_1simple_1_1ImageFileReader.html#a1bf76ba5013546821c278653c99d2b94) and[sitk::ImageFileReader::SetExtractSize](https://itk.org/SimpleITKDoxygen/html/classitk_1_1simple_1_1ImageFileReader.html#ae108978ac1c7b8953c01860d0bd30939) methods which allows setting a sub region of the image file to read. This can be used after the [sitk::ImageFileReader::ReadInformation](https://simpleitk.readthedocs.io/en/master/Examples/DicomImagePrintTags/Documentation.html) method has been called to determine the size and type of the image.

---

<div class="post-metadata">

### Author: ![ludicludo](https://discourse.itk.org/user_avatar/discourse.itk.org/ludicludo/32/526_2.png) [@ludicludo](https://discourse.itk.org/u/ludicludo)
#### Post date: [October 11, 2018, 9:14pm UTC](https://discourse.itk.org/t/jpg2000/1345/8 "2018-10-11T21:14:16Z")

</div>

Thank you very much.  
I will try to get this done and come back here to report how it’ll end.  
Regards.  
Ludovic

---

<div class="post-metadata">

### Author: ![ludicludo](https://discourse.itk.org/user_avatar/discourse.itk.org/ludicludo/32/526_2.png) [@ludicludo](https://discourse.itk.org/u/ludicludo)
#### Post date: [October 12, 2018, 10:01am UTC](https://discourse.itk.org/t/jpg2000/1345/9 "2018-10-12T10:01:56Z")

</div>

I had these warning during configuration process. I am not sure what does mean or if this will have an effect on my ITK installation with jpg2000 support

> Blockquote  
> CMake Error at Wrapping/Generators/SwigInterface/CMakeLists.txt:377  
> (add\_dependencies):  
> The dependency target “ITKIOJPEG2000Swig” of target “ITKReviewSwig” does  
> not exist.  
> Call Stack (most recent call first):  
> Wrapping/Generators/CMakeLists.txt:87 (itk\_end\_wrap\_module\_swig\_interface)  
> Wrapping/TypedefMacros.cmake:123 (itk\_end\_wrap\_module\_all\_generators)  
> Modules/Nonunit/Review/wrapping/CMakeLists.txt:3 (itk\_end\_wrap\_module)

CMake Error at Wrapping/Generators/Python/CMakeLists.txt:556  
(add\_dependencies):  
The dependency target “ITKIOJPEG2000Swig” of target “ITKReviewPython” does  
not exist.  
Call Stack (most recent call first):  
Wrapping/Generators/CMakeLists.txt:90 (itk\_end\_wrap\_module\_python)  
Wrapping/TypedefMacros.cmake:123 (itk\_end\_wrap\_module\_all\_generators)

Regards  
Ludovic

---

<div class="post-metadata">

### Author: ![ludicludo](https://discourse.itk.org/user_avatar/discourse.itk.org/ludicludo/32/526_2.png) [@ludicludo](https://discourse.itk.org/u/ludicludo)
#### Post date: [October 12, 2018, 11:42am UTC](https://discourse.itk.org/t/jpg2000/1345/10 "2018-10-12T11:42:07Z")

</div>

Hi,  
Apparently, a header file is missing in my installation

> Blockquote  
> /ITK/Modules/IO/JPEG2000/include/itkJPEG2000ImageIO.h:23:33: fatal error: ITKIOJPEG2000Export.h: Aucun fichier ou dossier de ce type  
> compilation terminated.

Maybe, I am doing something wrong while getting the patch ?  
Regards  
Ludovic

---

<div class="post-metadata">

### Author: ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)
#### Post date: [October 12, 2018, 12:13pm UTC](https://discourse.itk.org/t/jpg2000/1345/11 "2018-10-12T12:13:07Z")

</div>

That error is reported by the itk gerrit robots. I was unable to reproduce it yesterday.

I’ll look into it today, do you the configuration you used?

---

<div class="post-metadata">

### Author: ![ludicludo](https://discourse.itk.org/user_avatar/discourse.itk.org/ludicludo/32/526_2.png) [@ludicludo](https://discourse.itk.org/u/ludicludo)
#### Post date: [October 12, 2018, 2:45pm UTC](https://discourse.itk.org/t/jpg2000/1345/12 "2018-10-12T14:45:10Z")

</div>

Hi,  
Configuration ? you mean CMakeCache.txt or OS and the like ?

---

<div class="post-metadata">

### Author: ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)
#### Post date: [October 12, 2018, 2:47pm UTC](https://discourse.itk.org/t/jpg2000/1345/13 "2018-10-12T14:47:32Z")

</div>

I was able to find the problem with the patch and it is fixed in the patch/4 now: [http://review.source.kitware.com/#/c/23803/4](http://review.source.kitware.com/#/c/23803/4)

It was a silly case issue with a filename.

---

<div class="post-metadata">

### Author: ![ludicludo](https://discourse.itk.org/user_avatar/discourse.itk.org/ludicludo/32/526_2.png) [@ludicludo](https://discourse.itk.org/u/ludicludo)
#### Post date: [October 14, 2018, 4:13am UTC](https://discourse.itk.org/t/jpg2000/1345/14 "2018-10-14T04:13:20Z")

</div>

Hi,  
OK, your patches made the compilation successful. However, when I want to wrap itk5 with python, I got an additional error at compilation time:

> Wrapping/Typedefs/itkJPEG2000ImageIO.i:29: Warning 401: Nothing known about base class ‘itk::StreamingImageIOBase’. Ignored.  
> /home/physiciens/itk\_5/build/Wrapping/Typedefs/itkJPEG2000ImageIO.i:54: Warning 401: Nothing known about base class ‘itk::ObjectFactoryBase’. Ignored

BTW, thank you for effort.  
Regards  
Ludovic

---

<div class="post-metadata">

### Author: ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)
#### Post date: [October 15, 2018, 1:50pm UTC](https://discourse.itk.org/t/jpg2000/1345/15 "2018-10-15T13:50:54Z")

</div>

Have you tried building SimpleITK against the patched version of ITK?

---

<div class="post-metadata">

### Author: ![ludicludo](https://discourse.itk.org/user_avatar/discourse.itk.org/ludicludo/32/526_2.png) [@ludicludo](https://discourse.itk.org/u/ludicludo)
#### Post date: [October 15, 2018, 7:38pm UTC](https://discourse.itk.org/t/jpg2000/1345/16 "2018-10-15T19:38:34Z")

</div>

Hi,  
Not yet. I was thinking first to give a try to itk as it appears to be more complete than simpleitk.  
Do you think I should go with SimpleITK first ?  
Regards  
Ludovic

---

<div class="post-metadata">

### Author: ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)
#### Post date: [October 15, 2018, 8:18pm UTC](https://discourse.itk.org/t/jpg2000/1345/17 "2018-10-15T20:18:06Z")

</div>

> [@ludicludo](#):
>
> Do you think I should go with SimpleITK first ?

I am a SimpleITK developer. The patch has been merged into ITK master. The recommended configuration for SimpleITK below, enables reading of JPEG2000 images. It worked for me.

> [@blowekamp](#):
>
> cmake -DModule\_ITKIOJPEG2000:BOOL=ON -DCMAKE\_CXX\_STANDARD:STRING=11 -DITK\_GIT\_TAG:STRING=master -DITKV4\_COMPATIBILITY:BOOL=ON -DITK\_LEGACY\_REMOVE:BOOL=OFF SimpleITK/SuperBuild

---

<div class="post-metadata">

### Author: ![ludicludo](https://discourse.itk.org/user_avatar/discourse.itk.org/ludicludo/32/526_2.png) [@ludicludo](https://discourse.itk.org/u/ludicludo)
#### Post date: [October 16, 2018, 5:08am UTC](https://discourse.itk.org/t/jpg2000/1345/18 "2018-10-16T05:08:50Z")

</div>

Hi,  
I used the line you provided me and compiled successfully once configuration finished. i create a virtual environment inside the compiled tree. But still, sitk.ReadImage doesn’t open my file .

> sitk::ERROR: Unable to determine ImageIO reader for “./07\_test\_14.jp2”

I suspect I’m doing something wrong or missing something because sitk.Version() pointed me to 4.13 version. I thought we were on the 5th.

I got sitk source from git repository via clone command. BTW, I saw your last commit few days ago, but apparently not the ones on jpg2000. But, I may be wrong.  
Regards  
Ludovic

---

<div class="post-metadata">

### Author: ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)
#### Post date: [October 16, 2018, 2:19pm UTC](https://discourse.itk.org/t/jpg2000/1345/19 "2018-10-16T14:19:19Z")

</div>

What is the output of the following command: `python -c "import SimpleITK as sitk; print(sitk.ImageFileReader())"` I am getting the following:

```auto
itk::simple::ImageFileReader
  FileName: ""
  ExtractSize: []
  ExtractIndex: []
  Image Information:
    PixelType: Unknown pixel id
    Dimension: 0
    NumberOfComponents: 0
    Direction: []
    Origin: []
    Spacing: []
    Size: []
  OutputPixelType: Unknown pixel id
  LoadPrivateTags: 0
  ImageIOName: 
  Registered ImageIO:
	BMPImageIO ( *.bmp, *.BMP )
	BioRadImageIO ( *.PIC, *.pic )
	Bruker2dseqImageIO
	GDCMImageIO ( *.dcm, *.DCM, *.dicom, *.DICOM )
	GE4ImageIO
	GE5ImageIO
	GiplImageIO
	HDF5ImageIO ( *.hdf, *.h4, *.hdf4, *.h5, *.hdf5, *.he4, *.he5, *.hd5 )
	JPEGImageIO ( *.jpg, *.JPG, *.jpeg, *.JPEG )
	JPEG2000ImageIO ( *.j2k, *.jp2, *.jpt )
	LSMImageIO ( *.tif, *.TIF, *.tiff, *.TIFF, *.lsm, *.LSM )
	MINCImageIO ( *.mnc, *.MNC, *.mnc2, *.MNC2 )
	MRCImageIO ( *.mrc, *.rec )
	MetaImageIO ( *.mha, *.mhd )
	NiftiImageIO ( *.nia, *.nii, *.nii.gz, *.hdr, *.img, *.img.gz )
	NrrdImageIO ( *.nrrd, *.nhdr )
	PNGImageIO ( *.png, *.PNG )
	SCIFIOImageIO
	StimulateImageIO ( *.spr )
	TIFFImageIO ( *.tif, *.TIF, *.tiff, *.TIFF )
	VTKImageIO ( *.vtk )
  Debug: 0
  NumberOfThreads: 88
  Commands: (none)
  ProgressMeasurement: 0
  ActiveProcess: (none)

```

This shows that the JPEG2000ImageIO is registered. If this is not there then inspect your build directory to verify that the new ITKIOJPEG2000 modules exists and is enabled in the ITK build directory. Try the following:

```auto
$grep Module_ITKIOJPEG2000 ITK-build/CMakeCache.txt 
Module_ITKIOJPEG2000:BOOL=ON
//ADVANCED property for variable: Module_ITKIOJPEG2000
Module_ITKIOJPEG2000-ADVANCED:INTERNAL=1

```

I tried the recommended command again and it works. So verify you are using and have installed the version of SimpleITK you just compiled.

---

<div class="post-metadata">

### Author: ![ludicludo](https://discourse.itk.org/user_avatar/discourse.itk.org/ludicludo/32/526_2.png) [@ludicludo](https://discourse.itk.org/u/ludicludo)
#### Post date: [October 17, 2018, 6:54pm UTC](https://discourse.itk.org/t/jpg2000/1345/20 "2018-10-17T18:54:22Z")

</div>

Hi,  
Unfortunately, JP2000 is absent from the ImageFileReader list.

> Registered ImageIO:  
> BMPImageIO ( \*.bmp, \*.BMP )  
> BioRadImageIO ( \*.PIC, \*.pic )  
> Bruker2dseqImageIO  
> GDCMImageIO  
> GE4ImageIO  
> GE5ImageIO  
> GiplImageIO  
> HDF5ImageIO  
> JPEGImageIO ( \*.jpg, \*.JPG, \*.jpeg, \*.JPEG )  
> LSMImageIO ( \*.tif, \*.TIF, \*.tiff, \*.TIFF, \*.lsm, \*.LSM )  
> MINCImageIO ( \*.mnc, \*.MNC )  
> MRCImageIO ( \*.mrc, \*.rec )  
> MetaImageIO ( \*.mha, \*.mhd )  
> NiftiImageIO ( \*.nia, \*.nii, \*.nii.gz, \*.hdr, \*.img, \*.img.gz )  
> NrrdImageIO ( \*.nrrd, \*.nhdr )  
> PNGImageIO ( \*.png, \*.PNG )  
> StimulateImageIO  
> TIFFImageIO ( \*.tif, \*.TIF, \*.tiff, \*.TIFF )  
> VTKImageIO ( \*.vtk )

But, this feature is enable in the ITK build directory

> grep Module\_ITKIOJPEG2000 ITK-build/CMakeCache.txt  
> Module\_ITKIOJPEG2000:BOOL=ON  
> //ADVANCED property for variable: Module\_ITKIOJPEG2000  
> Module\_ITKIOJPEG2000-ADVANCED:INTERNAL=1

Regarding tne installation of SimpleITK right after the compilation, I tried a command `make install` but no such rule is present in the make file. I guessed it was correct since we used Superbuild feature.  
So, how do you install the just compiled SimpleITK and ITK in your python environment ? I guess I must copy some wheels or shared libraries. But is there any automatic process to do it ?  
Many thanks  
regards  
Ludovic

[Next page](https://discourse.itk.org/t/jpg2000/1345.md?page=2)
