skimage: defining vertical shear










2















Python skimage package has a function transform.AffineTransform() where one of the options is shear which does horizontal shear.



Obviously, I can do a vertical shear by switching axes back and forth. This is what I do:



from skimage import data, transform
import matplotlib.pyplot as plt
import numpy as np

img = data.astronaut()/255

v = 0.3

tf = transform.AffineTransform(shear=-v)
img2 = transform.warp(img, tf, order=1, preserve_range=True, mode='constant')

img3 = np.swapaxes(img, 0, 1)
img3 = transform.warp(img3, tf, order=1, preserve_range=True, mode='constant')
img3 = np.swapaxes(img3, 0, 1)

plt.imshow(np.hstack([img, img2, img3]))
plt.show()


shear



Anyway, I am surprised there is no more direct way to define a vertical shear option... Am I mistaken?










share|improve this question


























    2















    Python skimage package has a function transform.AffineTransform() where one of the options is shear which does horizontal shear.



    Obviously, I can do a vertical shear by switching axes back and forth. This is what I do:



    from skimage import data, transform
    import matplotlib.pyplot as plt
    import numpy as np

    img = data.astronaut()/255

    v = 0.3

    tf = transform.AffineTransform(shear=-v)
    img2 = transform.warp(img, tf, order=1, preserve_range=True, mode='constant')

    img3 = np.swapaxes(img, 0, 1)
    img3 = transform.warp(img3, tf, order=1, preserve_range=True, mode='constant')
    img3 = np.swapaxes(img3, 0, 1)

    plt.imshow(np.hstack([img, img2, img3]))
    plt.show()


    shear



    Anyway, I am surprised there is no more direct way to define a vertical shear option... Am I mistaken?










    share|improve this question
























      2












      2








      2


      1






      Python skimage package has a function transform.AffineTransform() where one of the options is shear which does horizontal shear.



      Obviously, I can do a vertical shear by switching axes back and forth. This is what I do:



      from skimage import data, transform
      import matplotlib.pyplot as plt
      import numpy as np

      img = data.astronaut()/255

      v = 0.3

      tf = transform.AffineTransform(shear=-v)
      img2 = transform.warp(img, tf, order=1, preserve_range=True, mode='constant')

      img3 = np.swapaxes(img, 0, 1)
      img3 = transform.warp(img3, tf, order=1, preserve_range=True, mode='constant')
      img3 = np.swapaxes(img3, 0, 1)

      plt.imshow(np.hstack([img, img2, img3]))
      plt.show()


      shear



      Anyway, I am surprised there is no more direct way to define a vertical shear option... Am I mistaken?










      share|improve this question














      Python skimage package has a function transform.AffineTransform() where one of the options is shear which does horizontal shear.



      Obviously, I can do a vertical shear by switching axes back and forth. This is what I do:



      from skimage import data, transform
      import matplotlib.pyplot as plt
      import numpy as np

      img = data.astronaut()/255

      v = 0.3

      tf = transform.AffineTransform(shear=-v)
      img2 = transform.warp(img, tf, order=1, preserve_range=True, mode='constant')

      img3 = np.swapaxes(img, 0, 1)
      img3 = transform.warp(img3, tf, order=1, preserve_range=True, mode='constant')
      img3 = np.swapaxes(img3, 0, 1)

      plt.imshow(np.hstack([img, img2, img3]))
      plt.show()


      shear



      Anyway, I am surprised there is no more direct way to define a vertical shear option... Am I mistaken?







      python scikit-image






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 14 '18 at 10:55









      Ricardo CruzRicardo Cruz

      1,43521941




      1,43521941






















          1 Answer
          1






          active

          oldest

          votes


















          2














          Your question (and linked page) holds the answer... as AffineTransform allows you to specify the transformation matrix, and your linked wiki page shows what this is, it is pretty straight forward to reduce the number of operations by directly specifying the transformation matrix, e.g.



          from skimage import data, transform
          import matplotlib.pyplot as plt
          import numpy as np

          img = data.astronaut()/255

          v = 0.3

          tf = transform.AffineTransform(shear=-v)
          img2 = transform.warp(img, tf, order=1, preserve_range=True, mode='constant')

          img3 = np.swapaxes(img, 0, 1)
          img3 = transform.warp(img3, tf, order=1, preserve_range=True, mode='constant')
          img3 = np.swapaxes(img3, 0, 1)

          plt.imshow(np.hstack([img, img2, img3]))

          # Using the transformation matrix directly...

          tf_h = transform.AffineTransform(
          np.array([[1, 0.3, 0], [0, 1, 0], [0, 0, 1]]))
          img4 = transform.warp(img, tf, order=1, preserve_range=True, mode='constant')
          tf_v = transform.AffineTransform(
          np.array([[1, 0, 0], [0.3, 1, 0], [0, 0, 1]]))
          img4 = transform.warp(img, tf_h, order=1, preserve_range=True, mode='constant')
          img5 = transform.warp(img, tf_v, order=1, preserve_range=True, mode='constant')

          plt.figure()
          plt.imshow(np.hstack([img, img4, img5]))

          plt.show()


          You should see two figures with the same set of images.






          share|improve this answer























          • Thanks. When using PIL, I also specify the matrix. I was surprised there was no vertical shear parameter in scikit-image which is generally more user-friendly. I will just wait to see if someone knows of a more direct way to do it, otherwise I will give you the correct answer, it's great!

            – Ricardo Cruz
            Nov 14 '18 at 15:40











          • @RicardoCruz - if you look at the source (specifically here: github.com/scikit-image/scikit-image/blob/master/skimage/… ) you'll see that at least as far as AffineTransform is concerned, it definitely only supports horizontal shear.

            – jmetz
            Nov 15 '18 at 12:22











          • @RicardoCruz: Also be aware that there is a little controversy about the shear argument at the moment: github.com/scikit-image/scikit-image/issues/3239 - you might want to stick to defining the transformation matrix for now anyway!

            – jmetz
            Nov 15 '18 at 13:00











          • Thank you for the heads up!

            – Ricardo Cruz
            Nov 15 '18 at 23:02










          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%2f53298558%2fskimage-defining-vertical-shear%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









          2














          Your question (and linked page) holds the answer... as AffineTransform allows you to specify the transformation matrix, and your linked wiki page shows what this is, it is pretty straight forward to reduce the number of operations by directly specifying the transformation matrix, e.g.



          from skimage import data, transform
          import matplotlib.pyplot as plt
          import numpy as np

          img = data.astronaut()/255

          v = 0.3

          tf = transform.AffineTransform(shear=-v)
          img2 = transform.warp(img, tf, order=1, preserve_range=True, mode='constant')

          img3 = np.swapaxes(img, 0, 1)
          img3 = transform.warp(img3, tf, order=1, preserve_range=True, mode='constant')
          img3 = np.swapaxes(img3, 0, 1)

          plt.imshow(np.hstack([img, img2, img3]))

          # Using the transformation matrix directly...

          tf_h = transform.AffineTransform(
          np.array([[1, 0.3, 0], [0, 1, 0], [0, 0, 1]]))
          img4 = transform.warp(img, tf, order=1, preserve_range=True, mode='constant')
          tf_v = transform.AffineTransform(
          np.array([[1, 0, 0], [0.3, 1, 0], [0, 0, 1]]))
          img4 = transform.warp(img, tf_h, order=1, preserve_range=True, mode='constant')
          img5 = transform.warp(img, tf_v, order=1, preserve_range=True, mode='constant')

          plt.figure()
          plt.imshow(np.hstack([img, img4, img5]))

          plt.show()


          You should see two figures with the same set of images.






          share|improve this answer























          • Thanks. When using PIL, I also specify the matrix. I was surprised there was no vertical shear parameter in scikit-image which is generally more user-friendly. I will just wait to see if someone knows of a more direct way to do it, otherwise I will give you the correct answer, it's great!

            – Ricardo Cruz
            Nov 14 '18 at 15:40











          • @RicardoCruz - if you look at the source (specifically here: github.com/scikit-image/scikit-image/blob/master/skimage/… ) you'll see that at least as far as AffineTransform is concerned, it definitely only supports horizontal shear.

            – jmetz
            Nov 15 '18 at 12:22











          • @RicardoCruz: Also be aware that there is a little controversy about the shear argument at the moment: github.com/scikit-image/scikit-image/issues/3239 - you might want to stick to defining the transformation matrix for now anyway!

            – jmetz
            Nov 15 '18 at 13:00











          • Thank you for the heads up!

            – Ricardo Cruz
            Nov 15 '18 at 23:02















          2














          Your question (and linked page) holds the answer... as AffineTransform allows you to specify the transformation matrix, and your linked wiki page shows what this is, it is pretty straight forward to reduce the number of operations by directly specifying the transformation matrix, e.g.



          from skimage import data, transform
          import matplotlib.pyplot as plt
          import numpy as np

          img = data.astronaut()/255

          v = 0.3

          tf = transform.AffineTransform(shear=-v)
          img2 = transform.warp(img, tf, order=1, preserve_range=True, mode='constant')

          img3 = np.swapaxes(img, 0, 1)
          img3 = transform.warp(img3, tf, order=1, preserve_range=True, mode='constant')
          img3 = np.swapaxes(img3, 0, 1)

          plt.imshow(np.hstack([img, img2, img3]))

          # Using the transformation matrix directly...

          tf_h = transform.AffineTransform(
          np.array([[1, 0.3, 0], [0, 1, 0], [0, 0, 1]]))
          img4 = transform.warp(img, tf, order=1, preserve_range=True, mode='constant')
          tf_v = transform.AffineTransform(
          np.array([[1, 0, 0], [0.3, 1, 0], [0, 0, 1]]))
          img4 = transform.warp(img, tf_h, order=1, preserve_range=True, mode='constant')
          img5 = transform.warp(img, tf_v, order=1, preserve_range=True, mode='constant')

          plt.figure()
          plt.imshow(np.hstack([img, img4, img5]))

          plt.show()


          You should see two figures with the same set of images.






          share|improve this answer























          • Thanks. When using PIL, I also specify the matrix. I was surprised there was no vertical shear parameter in scikit-image which is generally more user-friendly. I will just wait to see if someone knows of a more direct way to do it, otherwise I will give you the correct answer, it's great!

            – Ricardo Cruz
            Nov 14 '18 at 15:40











          • @RicardoCruz - if you look at the source (specifically here: github.com/scikit-image/scikit-image/blob/master/skimage/… ) you'll see that at least as far as AffineTransform is concerned, it definitely only supports horizontal shear.

            – jmetz
            Nov 15 '18 at 12:22











          • @RicardoCruz: Also be aware that there is a little controversy about the shear argument at the moment: github.com/scikit-image/scikit-image/issues/3239 - you might want to stick to defining the transformation matrix for now anyway!

            – jmetz
            Nov 15 '18 at 13:00











          • Thank you for the heads up!

            – Ricardo Cruz
            Nov 15 '18 at 23:02













          2












          2








          2







          Your question (and linked page) holds the answer... as AffineTransform allows you to specify the transformation matrix, and your linked wiki page shows what this is, it is pretty straight forward to reduce the number of operations by directly specifying the transformation matrix, e.g.



          from skimage import data, transform
          import matplotlib.pyplot as plt
          import numpy as np

          img = data.astronaut()/255

          v = 0.3

          tf = transform.AffineTransform(shear=-v)
          img2 = transform.warp(img, tf, order=1, preserve_range=True, mode='constant')

          img3 = np.swapaxes(img, 0, 1)
          img3 = transform.warp(img3, tf, order=1, preserve_range=True, mode='constant')
          img3 = np.swapaxes(img3, 0, 1)

          plt.imshow(np.hstack([img, img2, img3]))

          # Using the transformation matrix directly...

          tf_h = transform.AffineTransform(
          np.array([[1, 0.3, 0], [0, 1, 0], [0, 0, 1]]))
          img4 = transform.warp(img, tf, order=1, preserve_range=True, mode='constant')
          tf_v = transform.AffineTransform(
          np.array([[1, 0, 0], [0.3, 1, 0], [0, 0, 1]]))
          img4 = transform.warp(img, tf_h, order=1, preserve_range=True, mode='constant')
          img5 = transform.warp(img, tf_v, order=1, preserve_range=True, mode='constant')

          plt.figure()
          plt.imshow(np.hstack([img, img4, img5]))

          plt.show()


          You should see two figures with the same set of images.






          share|improve this answer













          Your question (and linked page) holds the answer... as AffineTransform allows you to specify the transformation matrix, and your linked wiki page shows what this is, it is pretty straight forward to reduce the number of operations by directly specifying the transformation matrix, e.g.



          from skimage import data, transform
          import matplotlib.pyplot as plt
          import numpy as np

          img = data.astronaut()/255

          v = 0.3

          tf = transform.AffineTransform(shear=-v)
          img2 = transform.warp(img, tf, order=1, preserve_range=True, mode='constant')

          img3 = np.swapaxes(img, 0, 1)
          img3 = transform.warp(img3, tf, order=1, preserve_range=True, mode='constant')
          img3 = np.swapaxes(img3, 0, 1)

          plt.imshow(np.hstack([img, img2, img3]))

          # Using the transformation matrix directly...

          tf_h = transform.AffineTransform(
          np.array([[1, 0.3, 0], [0, 1, 0], [0, 0, 1]]))
          img4 = transform.warp(img, tf, order=1, preserve_range=True, mode='constant')
          tf_v = transform.AffineTransform(
          np.array([[1, 0, 0], [0.3, 1, 0], [0, 0, 1]]))
          img4 = transform.warp(img, tf_h, order=1, preserve_range=True, mode='constant')
          img5 = transform.warp(img, tf_v, order=1, preserve_range=True, mode='constant')

          plt.figure()
          plt.imshow(np.hstack([img, img4, img5]))

          plt.show()


          You should see two figures with the same set of images.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 14 '18 at 12:24









          jmetzjmetz

          7,79231832




          7,79231832












          • Thanks. When using PIL, I also specify the matrix. I was surprised there was no vertical shear parameter in scikit-image which is generally more user-friendly. I will just wait to see if someone knows of a more direct way to do it, otherwise I will give you the correct answer, it's great!

            – Ricardo Cruz
            Nov 14 '18 at 15:40











          • @RicardoCruz - if you look at the source (specifically here: github.com/scikit-image/scikit-image/blob/master/skimage/… ) you'll see that at least as far as AffineTransform is concerned, it definitely only supports horizontal shear.

            – jmetz
            Nov 15 '18 at 12:22











          • @RicardoCruz: Also be aware that there is a little controversy about the shear argument at the moment: github.com/scikit-image/scikit-image/issues/3239 - you might want to stick to defining the transformation matrix for now anyway!

            – jmetz
            Nov 15 '18 at 13:00











          • Thank you for the heads up!

            – Ricardo Cruz
            Nov 15 '18 at 23:02

















          • Thanks. When using PIL, I also specify the matrix. I was surprised there was no vertical shear parameter in scikit-image which is generally more user-friendly. I will just wait to see if someone knows of a more direct way to do it, otherwise I will give you the correct answer, it's great!

            – Ricardo Cruz
            Nov 14 '18 at 15:40











          • @RicardoCruz - if you look at the source (specifically here: github.com/scikit-image/scikit-image/blob/master/skimage/… ) you'll see that at least as far as AffineTransform is concerned, it definitely only supports horizontal shear.

            – jmetz
            Nov 15 '18 at 12:22











          • @RicardoCruz: Also be aware that there is a little controversy about the shear argument at the moment: github.com/scikit-image/scikit-image/issues/3239 - you might want to stick to defining the transformation matrix for now anyway!

            – jmetz
            Nov 15 '18 at 13:00











          • Thank you for the heads up!

            – Ricardo Cruz
            Nov 15 '18 at 23:02
















          Thanks. When using PIL, I also specify the matrix. I was surprised there was no vertical shear parameter in scikit-image which is generally more user-friendly. I will just wait to see if someone knows of a more direct way to do it, otherwise I will give you the correct answer, it's great!

          – Ricardo Cruz
          Nov 14 '18 at 15:40





          Thanks. When using PIL, I also specify the matrix. I was surprised there was no vertical shear parameter in scikit-image which is generally more user-friendly. I will just wait to see if someone knows of a more direct way to do it, otherwise I will give you the correct answer, it's great!

          – Ricardo Cruz
          Nov 14 '18 at 15:40













          @RicardoCruz - if you look at the source (specifically here: github.com/scikit-image/scikit-image/blob/master/skimage/… ) you'll see that at least as far as AffineTransform is concerned, it definitely only supports horizontal shear.

          – jmetz
          Nov 15 '18 at 12:22





          @RicardoCruz - if you look at the source (specifically here: github.com/scikit-image/scikit-image/blob/master/skimage/… ) you'll see that at least as far as AffineTransform is concerned, it definitely only supports horizontal shear.

          – jmetz
          Nov 15 '18 at 12:22













          @RicardoCruz: Also be aware that there is a little controversy about the shear argument at the moment: github.com/scikit-image/scikit-image/issues/3239 - you might want to stick to defining the transformation matrix for now anyway!

          – jmetz
          Nov 15 '18 at 13:00





          @RicardoCruz: Also be aware that there is a little controversy about the shear argument at the moment: github.com/scikit-image/scikit-image/issues/3239 - you might want to stick to defining the transformation matrix for now anyway!

          – jmetz
          Nov 15 '18 at 13:00













          Thank you for the heads up!

          – Ricardo Cruz
          Nov 15 '18 at 23:02





          Thank you for the heads up!

          – Ricardo Cruz
          Nov 15 '18 at 23:02



















          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%2f53298558%2fskimage-defining-vertical-shear%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

          Use pre created SQLite database for Android project in kotlin

          Darth Vader #20

          Ondo