What is an 'cv2.reg_MapperGradEuclid' object? (OpenCV)












0















I am trying to do some image registration with OpenCV 4 and Python 3.6. Two dicom files are loaded and the pixel data is handled as numpy.ndarray. When I try to pass these arrays to the cv2.reg_MapperGradEuclid.calculate() function, the following error is raised:




descriptor 'calculate' requires a cv2.reg_MapperGradEuclid object
but received a 'numpy.ndarray'




I looked up the documentation and several threads, all I found was that there should be two InputArray ´s that should be of the BGR type(?) and that technically np.ndarray should work.



    import numpy as np    
import pydicom
import cv2

file1="one.DCM"
file2="two.DCM"
data1 = pydicom.read_file(file1)
data2 = pydicom.read_file(file2)

PixelArrayBelow = data1.pixel_array #type np.ndarray
PixelArrayAbove = data2.pixel_array

PixelArrayBelow=PixelArrayBelow.astype(np.float32)
PixelArrayAbove=PixelArrayAbove.astype(np.float32)

BelowNew=cv2.cvtColor(PixelArrayBelow,cv2.COLOR_GRAY2BGR)
AboveNew=cv2.cvtColor(PixelArrayAbove,cv2.COLOR_GRAY2BGR)

b = cv2.reg_MapperGradEuclid.calculate(BelowNew,AboveNew)
print(b)


I expected it to print some combination of translation and rotation vector/matrix, but the above mentioned error occured.










share|improve this question





























    0















    I am trying to do some image registration with OpenCV 4 and Python 3.6. Two dicom files are loaded and the pixel data is handled as numpy.ndarray. When I try to pass these arrays to the cv2.reg_MapperGradEuclid.calculate() function, the following error is raised:




    descriptor 'calculate' requires a cv2.reg_MapperGradEuclid object
    but received a 'numpy.ndarray'




    I looked up the documentation and several threads, all I found was that there should be two InputArray ´s that should be of the BGR type(?) and that technically np.ndarray should work.



        import numpy as np    
    import pydicom
    import cv2

    file1="one.DCM"
    file2="two.DCM"
    data1 = pydicom.read_file(file1)
    data2 = pydicom.read_file(file2)

    PixelArrayBelow = data1.pixel_array #type np.ndarray
    PixelArrayAbove = data2.pixel_array

    PixelArrayBelow=PixelArrayBelow.astype(np.float32)
    PixelArrayAbove=PixelArrayAbove.astype(np.float32)

    BelowNew=cv2.cvtColor(PixelArrayBelow,cv2.COLOR_GRAY2BGR)
    AboveNew=cv2.cvtColor(PixelArrayAbove,cv2.COLOR_GRAY2BGR)

    b = cv2.reg_MapperGradEuclid.calculate(BelowNew,AboveNew)
    print(b)


    I expected it to print some combination of translation and rotation vector/matrix, but the above mentioned error occured.










    share|improve this question



























      0












      0








      0








      I am trying to do some image registration with OpenCV 4 and Python 3.6. Two dicom files are loaded and the pixel data is handled as numpy.ndarray. When I try to pass these arrays to the cv2.reg_MapperGradEuclid.calculate() function, the following error is raised:




      descriptor 'calculate' requires a cv2.reg_MapperGradEuclid object
      but received a 'numpy.ndarray'




      I looked up the documentation and several threads, all I found was that there should be two InputArray ´s that should be of the BGR type(?) and that technically np.ndarray should work.



          import numpy as np    
      import pydicom
      import cv2

      file1="one.DCM"
      file2="two.DCM"
      data1 = pydicom.read_file(file1)
      data2 = pydicom.read_file(file2)

      PixelArrayBelow = data1.pixel_array #type np.ndarray
      PixelArrayAbove = data2.pixel_array

      PixelArrayBelow=PixelArrayBelow.astype(np.float32)
      PixelArrayAbove=PixelArrayAbove.astype(np.float32)

      BelowNew=cv2.cvtColor(PixelArrayBelow,cv2.COLOR_GRAY2BGR)
      AboveNew=cv2.cvtColor(PixelArrayAbove,cv2.COLOR_GRAY2BGR)

      b = cv2.reg_MapperGradEuclid.calculate(BelowNew,AboveNew)
      print(b)


      I expected it to print some combination of translation and rotation vector/matrix, but the above mentioned error occured.










      share|improve this question
















      I am trying to do some image registration with OpenCV 4 and Python 3.6. Two dicom files are loaded and the pixel data is handled as numpy.ndarray. When I try to pass these arrays to the cv2.reg_MapperGradEuclid.calculate() function, the following error is raised:




      descriptor 'calculate' requires a cv2.reg_MapperGradEuclid object
      but received a 'numpy.ndarray'




      I looked up the documentation and several threads, all I found was that there should be two InputArray ´s that should be of the BGR type(?) and that technically np.ndarray should work.



          import numpy as np    
      import pydicom
      import cv2

      file1="one.DCM"
      file2="two.DCM"
      data1 = pydicom.read_file(file1)
      data2 = pydicom.read_file(file2)

      PixelArrayBelow = data1.pixel_array #type np.ndarray
      PixelArrayAbove = data2.pixel_array

      PixelArrayBelow=PixelArrayBelow.astype(np.float32)
      PixelArrayAbove=PixelArrayAbove.astype(np.float32)

      BelowNew=cv2.cvtColor(PixelArrayBelow,cv2.COLOR_GRAY2BGR)
      AboveNew=cv2.cvtColor(PixelArrayAbove,cv2.COLOR_GRAY2BGR)

      b = cv2.reg_MapperGradEuclid.calculate(BelowNew,AboveNew)
      print(b)


      I expected it to print some combination of translation and rotation vector/matrix, but the above mentioned error occured.







      python opencv types






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 3 at 12:51









      Matthijs

      1,2051427




      1,2051427










      asked Jan 3 at 12:26









      MettphysikMettphysik

      32




      32
























          1 Answer
          1






          active

          oldest

          votes


















          0














          If you create a reg_MapperGradEuclid() object first and then pass the images into the object it seems to work. You are not calling the object properly.



          import cv2

          im1 = <some numpy array>
          im2 = <some numpy array>

          mge_obj = cv2.reg_MapperGradEuclid()
          retval = mge_obj.calculate(im1, im2)


          So to make it work with your code change:



          b = cv2.reg_MapperGradEuclid.calculate(BelowNew,AboveNew)



          to:



          b = cv2.reg_MapperGradEuclid().calculate(BelowNew,AboveNew)



          The class documentation is here but it's quite basic.






          share|improve this answer
























          • Thanks a lot. Either the documentation lacks some very important things or I just cant find them, because the resulting registration Map, again, cannot be handled easily. Instead of a 'cv2.reg_MapAffine' I get a 'cv2.reg_Map'. Its not possible to read shift and linear transformation from the latter one.

            – Mettphysik
            Jan 3 at 14:37











          • does b = cv2.reg_MapperGradAffine().calculate(BelowNew,AboveNew) give you the right result?

            – D.Griffiths
            Jan 3 at 18:36











          • It didn´t, but reg.MapTypeCaster_toAffine() , which was again hidden somewhere in the Documentation did. Thanks anyways!

            – Mettphysik
            Jan 3 at 19:46














          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54022282%2fwhat-is-an-cv2-reg-mappergradeuclid-object-opencv%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          If you create a reg_MapperGradEuclid() object first and then pass the images into the object it seems to work. You are not calling the object properly.



          import cv2

          im1 = <some numpy array>
          im2 = <some numpy array>

          mge_obj = cv2.reg_MapperGradEuclid()
          retval = mge_obj.calculate(im1, im2)


          So to make it work with your code change:



          b = cv2.reg_MapperGradEuclid.calculate(BelowNew,AboveNew)



          to:



          b = cv2.reg_MapperGradEuclid().calculate(BelowNew,AboveNew)



          The class documentation is here but it's quite basic.






          share|improve this answer
























          • Thanks a lot. Either the documentation lacks some very important things or I just cant find them, because the resulting registration Map, again, cannot be handled easily. Instead of a 'cv2.reg_MapAffine' I get a 'cv2.reg_Map'. Its not possible to read shift and linear transformation from the latter one.

            – Mettphysik
            Jan 3 at 14:37











          • does b = cv2.reg_MapperGradAffine().calculate(BelowNew,AboveNew) give you the right result?

            – D.Griffiths
            Jan 3 at 18:36











          • It didn´t, but reg.MapTypeCaster_toAffine() , which was again hidden somewhere in the Documentation did. Thanks anyways!

            – Mettphysik
            Jan 3 at 19:46


















          0














          If you create a reg_MapperGradEuclid() object first and then pass the images into the object it seems to work. You are not calling the object properly.



          import cv2

          im1 = <some numpy array>
          im2 = <some numpy array>

          mge_obj = cv2.reg_MapperGradEuclid()
          retval = mge_obj.calculate(im1, im2)


          So to make it work with your code change:



          b = cv2.reg_MapperGradEuclid.calculate(BelowNew,AboveNew)



          to:



          b = cv2.reg_MapperGradEuclid().calculate(BelowNew,AboveNew)



          The class documentation is here but it's quite basic.






          share|improve this answer
























          • Thanks a lot. Either the documentation lacks some very important things or I just cant find them, because the resulting registration Map, again, cannot be handled easily. Instead of a 'cv2.reg_MapAffine' I get a 'cv2.reg_Map'. Its not possible to read shift and linear transformation from the latter one.

            – Mettphysik
            Jan 3 at 14:37











          • does b = cv2.reg_MapperGradAffine().calculate(BelowNew,AboveNew) give you the right result?

            – D.Griffiths
            Jan 3 at 18:36











          • It didn´t, but reg.MapTypeCaster_toAffine() , which was again hidden somewhere in the Documentation did. Thanks anyways!

            – Mettphysik
            Jan 3 at 19:46
















          0












          0








          0







          If you create a reg_MapperGradEuclid() object first and then pass the images into the object it seems to work. You are not calling the object properly.



          import cv2

          im1 = <some numpy array>
          im2 = <some numpy array>

          mge_obj = cv2.reg_MapperGradEuclid()
          retval = mge_obj.calculate(im1, im2)


          So to make it work with your code change:



          b = cv2.reg_MapperGradEuclid.calculate(BelowNew,AboveNew)



          to:



          b = cv2.reg_MapperGradEuclid().calculate(BelowNew,AboveNew)



          The class documentation is here but it's quite basic.






          share|improve this answer













          If you create a reg_MapperGradEuclid() object first and then pass the images into the object it seems to work. You are not calling the object properly.



          import cv2

          im1 = <some numpy array>
          im2 = <some numpy array>

          mge_obj = cv2.reg_MapperGradEuclid()
          retval = mge_obj.calculate(im1, im2)


          So to make it work with your code change:



          b = cv2.reg_MapperGradEuclid.calculate(BelowNew,AboveNew)



          to:



          b = cv2.reg_MapperGradEuclid().calculate(BelowNew,AboveNew)



          The class documentation is here but it's quite basic.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jan 3 at 13:51









          D.GriffithsD.Griffiths

          7461317




          7461317













          • Thanks a lot. Either the documentation lacks some very important things or I just cant find them, because the resulting registration Map, again, cannot be handled easily. Instead of a 'cv2.reg_MapAffine' I get a 'cv2.reg_Map'. Its not possible to read shift and linear transformation from the latter one.

            – Mettphysik
            Jan 3 at 14:37











          • does b = cv2.reg_MapperGradAffine().calculate(BelowNew,AboveNew) give you the right result?

            – D.Griffiths
            Jan 3 at 18:36











          • It didn´t, but reg.MapTypeCaster_toAffine() , which was again hidden somewhere in the Documentation did. Thanks anyways!

            – Mettphysik
            Jan 3 at 19:46





















          • Thanks a lot. Either the documentation lacks some very important things or I just cant find them, because the resulting registration Map, again, cannot be handled easily. Instead of a 'cv2.reg_MapAffine' I get a 'cv2.reg_Map'. Its not possible to read shift and linear transformation from the latter one.

            – Mettphysik
            Jan 3 at 14:37











          • does b = cv2.reg_MapperGradAffine().calculate(BelowNew,AboveNew) give you the right result?

            – D.Griffiths
            Jan 3 at 18:36











          • It didn´t, but reg.MapTypeCaster_toAffine() , which was again hidden somewhere in the Documentation did. Thanks anyways!

            – Mettphysik
            Jan 3 at 19:46



















          Thanks a lot. Either the documentation lacks some very important things or I just cant find them, because the resulting registration Map, again, cannot be handled easily. Instead of a 'cv2.reg_MapAffine' I get a 'cv2.reg_Map'. Its not possible to read shift and linear transformation from the latter one.

          – Mettphysik
          Jan 3 at 14:37





          Thanks a lot. Either the documentation lacks some very important things or I just cant find them, because the resulting registration Map, again, cannot be handled easily. Instead of a 'cv2.reg_MapAffine' I get a 'cv2.reg_Map'. Its not possible to read shift and linear transformation from the latter one.

          – Mettphysik
          Jan 3 at 14:37













          does b = cv2.reg_MapperGradAffine().calculate(BelowNew,AboveNew) give you the right result?

          – D.Griffiths
          Jan 3 at 18:36





          does b = cv2.reg_MapperGradAffine().calculate(BelowNew,AboveNew) give you the right result?

          – D.Griffiths
          Jan 3 at 18:36













          It didn´t, but reg.MapTypeCaster_toAffine() , which was again hidden somewhere in the Documentation did. Thanks anyways!

          – Mettphysik
          Jan 3 at 19:46







          It didn´t, but reg.MapTypeCaster_toAffine() , which was again hidden somewhere in the Documentation did. Thanks anyways!

          – Mettphysik
          Jan 3 at 19:46






















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54022282%2fwhat-is-an-cv2-reg-mappergradeuclid-object-opencv%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Mossoró

          Error while reading .h5 file using the rhdf5 package in R

          Pushsharp Apns notification error: 'InvalidToken'