Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explore adding RGBUS wrapping #207

Open
dzenanz opened this issue Dec 2, 2022 · 10 comments
Open

Explore adding RGBUS wrapping #207

dzenanz opened this issue Dec 2, 2022 · 10 comments

Comments

@dzenanz
Copy link
Member

dzenanz commented Dec 2, 2022

This is off by default. If we add it here, will support for that work properly? Are additional wrappings for Image, ImageToImageFilter, etc allowed to be in Montage's wheel?

Motivation: this module is frequently used with 16-bit RGB images.

@tbirdso
Copy link

tbirdso commented Dec 2, 2022

This is off by default. If we add it here, will support for that work properly? Are additional wrappings for Image, ImageToImageFilter, etc allowed to be in Montage's wheel?

Hi @dzenanz , yes, this can definitely be done. I imagine there is a strong motivation to keep RGB unsigned short pixel wrappings disabled for Python wheel distributions if it is not commonly used, as we are already pushing quite close to the 2GB limit for ITKPythonBuilds archives as-is. In that case ITKMontage is the correct place to add those wrappings.

ITKUltrasound is a good module to reference as an example, it adds additional wrappings for "list-of-indices" pixel types for itk.Image, itk.ImageToImageFilter, and derivative ITKUltrasound classes in its wheels. Try taking a look at these files:

https://github.com/KitwareMedical/ITKUltrasound/blob/master/wrapping/itkImageUltrasound.wrap

https://github.com/KitwareMedical/ITKUltrasound/blob/master/wrapping/itkImageToImageFilterUltrasound.wrap

If I recall correctly it is a requirement that the wrap file names in the module itself do not conflict with those in ITK, i.e. ITK has itkImage.wrap while ITKUltrasound has itkImageUltrasound.wrap.

@dzenanz
Copy link
Member Author

dzenanz commented Dec 2, 2022

@ZymUpc and @zhusihan-python, would one of you like to make a PR per Tom's suggestion?

Pseudocode of itkMontageExtraWrappings.wrap to be added here:

if (NOT ITK_WRAP_rgb_unsigned_short)
  message(STATUS "Enabling 16-bit RGB support in ITKMontage, despite it being disabled in ITK")
  # instantiate for RGBUS: Image, ImageToImageFilter, and other things needed for TileMerge
  # maybe also CastImageFilter, ImageFileReader, and ImageFileWriter
endif()

Instantiation code should similar to https://github.com/InsightSoftwareConsortium/ITKMontage/blob/master/wrapping/itkTileMergeImageFilter.wrap.

@zhusihan-python
Copy link

I would love to, but im not familiar with cpp and makefiles, i guess its like this, right?

if (NOT ITK_WRAP_rgb_unsigned_short)
  message(STATUS "Enabling 16-bit RGB support in ITKMontage, despite it being disabled in ITK")
  # instantiate for RGBUS: Image, ImageToImageFilter, and other things needed for TileMerge
  # maybe also CastImageFilter, ImageFileReader, and ImageFileWriter
  itk_wrap_class("itk::Image" POINTER)
    foreach(d ${ITK_WRAP_IMAGE_DIMS})
      itk_wrap_template("listitkIndex${d}${d}" "std::list< itk::Index< ${d} > >, ${d}")
    endforeach(d)
  itk_end_wrap_class()
  itk_wrap_class("itk::ImageToImageFilter" POINTER)
    foreach(d ${IMAGE_DIMS_EXCEPT_2})
      if(ITK_WRAP_vector_float AND ITKM_VIF${d} AND ITKM_VIF2)
        itk_wrap_template("${ITKM_VIF${d}}${ITKM_VIF2}" "${ITKT_VIF${d}},${ITKT_VIF2}")
      endif()
      if(ITK_WRAP_vector_double AND ITKM_VID${d} AND ITKM_VID2)
        itk_wrap_template("${ITKM_VID${d}}${ITKM_VID2}" "${ITKT_VID${d}},${ITKT_VID2}")
      endif()
      if(ITK_WRAP_vector_float AND ITK_WRAP_vector_double)
        # VectorImage(float) <-> VectorImage(double)
        if(ITKM_VIF${d} AND ITKM_VID2)
          itk_wrap_template("${ITKM_VIF${d}}${ITKM_VID2}" "${ITKT_VIF${d}},${ITKT_VID2}")
        endif()
        if(ITKM_VID${d} AND ITKM_VIF2)
          itk_wrap_template("${ITKM_VID${d}}${ITKM_VIF2}" "${ITKT_VID${d}},${ITKT_VIF2}")
        endif()
      endif()
    endforeach()
  itk_end_wrap_class()
endif()

if someone have the complete wrap file, i can help to compile itk montage on windows10 and ubuntu22

@Eamon-UCAS
Copy link

@dzenanz @zhusihan-python Thank you for your help. I'm happy to try this method

I'm sorry, but I have other things to do on Saturday and Sunday

I will try it as early as possible on Monday.

@BohriumKwong
Copy link

@zhusihan-python I have compiled itk itk-5.2.1.dev20210904 python packages in ubuntu 22(from python 3.6 to 3.9)with ITK_WRAP_rgb_unsigned_short :BOOL=ON that can use itk.RGBPixel[itk.US] method, but I want the support in itk-montage which is not available in Python Package Index (PyPI) , because I have the same problem in @ZymUpc 's issue(InsightSoftwareConsortium/ITK#3779). I will uploads to Baidu Net dist if you need these wheel files and related folders

@BohriumKwong
Copy link

BohriumKwong commented Dec 5, 2022

@dzenanz In my image processing,I need the method of itk.RGBPixel[itk.US] in itk and method of itk.TileConfiguration and itk.TileMergeImageFilter in itk-montage. I helped @ZymUpc to built the python packages he wanted , but the dependence on itk-montage is s against our background expectation. The sample code that we want is as below :

    image = itk.imread(filename,itk.RGBPixel[itk.US])
    dimension = 2
    stage_tiles = itk.TileConfiguration[dimension]()
    linear_size = stage_tiles.LinearSize()
    resampleF = itk.TileMergeImageFilter[itk.RGBPixel[itk.US]].New()

@zhusihan-python
Copy link

@zhusihan-python I have compiled itk itk-5.2.1.dev20210904 python packages in ubuntu 22(from python 3.6 to 3.9)with ITK_WRAP_rgb_unsigned_short :BOOL=ON that can use itk.RGBPixel[itk.US] method, but I want the support in itk-montage which is not available in Python Package Index (PyPI) , because I have the same problem in @ZymUpc 's issue(InsightSoftwareConsortium/ITK#3779). I will uploads to Baidu Net dist if you need these wheel files and related folders

first build itk with wrap_python on,
then build itk montage repo set ITK_DIR to itk build dir, it will generate ITKTileMergeImageFileterPython etc
then build itk montage example dir set ITK_DIR to itk build dir, it will get CompleteMontage.exe etc

this is from my personal experience build itk and itk montage on windows 10

@thewtex
Copy link
Member

thewtex commented Dec 5, 2022

Hi, for a 2D 16-bit RGB image, I recommend that we wrap itk-montage for itk.Image[itk.Vector[itk.F, 3], 2].

The code of @BohriumKwong becomes

image = itk.imread(filename, itk.Vector[itk.F, 3]) 

and the rest is the same.

Another option is, itk.VectorImage[itk.US, 2]. However, that may be much more work to implement. The start would be:

image = itk.imread(filename, itk.VariableLengthVector[itk.US]) 

Either way, we will be able to use the pre-built binary Python packages.

@Eamon-UCAS
Copy link

Hello, our ultimate goal is to achieve 2D 16 bit RGB image mosaic based on itk and itk-montage. We hope to use the following two lines of code correctly

 image = itk.imread(filename,itk.RGBPixel[itk.US])
 resampleF = itk.TileMergeImageFilter[type(image)].New()

Now I change the code to the following:

 image = itk.imread(filename, itk.Vector[itk.F, 3])
 resampleF = itk.TileMergeImageFilter[type(image)].New()

It seems that itk-montage (corresponding to itk. TileMergeImageFilter) does not support itk.Vector [itk.F, 3] type data. The itk-montage installed with pip install itk-montage==0.7.3 only supports the following data types:
image

Do you mean that we need to recompile itk-montage?

Hi, for a 2D 16-bit RGB image, I recommend that we wrap itk-montage for itk.Image[itk.Vector[itk.F, 3], 2].

The code of @BohriumKwong becomes

image = itk.imread(filename, itk.Vector[itk.F, 3]) 

and the rest is the same.

Another option is, itk.VectorImage[itk.US, 2]. However, that may be much more work to implement. The start would be:

image = itk.imread(filename, itk.VariableLengthVector[itk.US]) 

Either way, we will be able to use the pre-built binary Python packages.

@dzenanz
Copy link
Member Author

dzenanz commented Dec 7, 2022

wrap itk-montage for itk.Image[itk.Vector[itk.F, 3], 2]

This will probably not need further wrappings, like itk.Image[itk.RGBPixel[itk.US], 2] would. So the new wrapping file would be a lot simpler. Or simpler even, we would put the new instantiation definitions in the existing files (e.g. https://github.com/InsightSoftwareConsortium/ITKMontage/blob/master/wrapping/itkTileMergeImageFilter.wrap).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants