Code Monkey home page Code Monkey logo

Comments (13)

aleju avatar aleju commented on May 22, 2024 2

not yet, its on the todo list

from imgaug.

aleju avatar aleju commented on May 22, 2024 1

If you want one specific rotation in degrees use Affine(rotate=x) where x is the degrees, e.g. Affine(rotate=90) to rotate by 90 degrees. If you want the augmenter to select randomly from a list of degrees use from imgaug import parameters as iap and then Affine(rotate=iap.Choice([x1, x2, x3, ...])), e.g. Affine(rotate=iap.Choice([90, 180, 270])) to rotate each image by either 90 or 180 or 270 degrees. Note that the height and width of the image always stays the same.

from imgaug.

aleju avatar aleju commented on May 22, 2024

That's not part of the library currently. Your description sounds like you just want to have rotation by 90 degrees (shape (h,w) to (w,h))? Then you can just change Fliplr to use numpy's rot90 method, i.e. something like the following should work (but only with lists, not arrays):

class Rot90(Augmenter):
    def __init__(self, p=0, name=None, deterministic=False, random_state=None):
        super(Rot90, self).__init__(name=name, deterministic=deterministic, random_state=random_state)

        if ia.is_single_number(p):
            self.p = Binomial(p)
        elif isinstance(p, StochasticParameter):
            self.p = p
        else:
            raise Exception("Expected p to be int or float or StochasticParameter, got %s." % (type(p),))

    def _augment_images(self, images, random_state, parents, hooks):
        assert isinstance(image, list)
        nb_images = len(images)
        samples = self.p.draw_samples((nb_images,), random_state=random_state)
        for i in sm.xrange(nb_images):
            if samples[i] == 1:
                images[i] = np.rot90(images[i], k=1)
        return images

    def _augment_keypoints(self, keypoints_on_images, random_state, parents, hooks):
        nb_images = len(keypoints_on_images)
        samples = self.p.draw_samples((nb_images,), random_state=random_state)
        for i, keypoints_on_image in enumerate(keypoints_on_images):
            if samples[i] == 1:
                width, height = keypoints_on_image.shape[0:2]
                for keypoint in keypoints_on_image.keypoints:
                    keypoint.x, keypoint.y = keypoint.y, keypoint.x
                keypoints_on_image.shape = (width, height)
        return keypoints_on_images

    def get_parameters(self):
        return [self.p]

then just use aug = iaa.Rot90(0.5); images_aug = aug.augment_images([image1, image2]).

from imgaug.

RomanSteinberg avatar RomanSteinberg commented on May 22, 2024

Will you include this code in the library?

from imgaug.

ahmedmazari-dhatim avatar ahmedmazari-dhatim commented on May 22, 2024

@aleju ,
when l run :
aug = iaa.Rot90(0.5); images_aug = aug.augment_images([image1, image2])

l get the following error

Traceback (most recent call last):
  File "/home/ahmed/imgaug/test_simple.py", line 47, in <module>
    images_aug = seq.augment_images(image)
  File "/home/ahmed/imgaug/imgaug/augmenters.py", line 244, in augment_images
    hooks=hooks
  File "/home/ahmed/imgaug/imgaug/augmenters.py", line 4349, in _augment_images
    assert isinstance(image, list)
NameError: global name 'image' is not defined

from imgaug.

RomanSteinberg avatar RomanSteinberg commented on May 22, 2024

l get the following error

It just a misspelling. It should be images variable for sure.

from imgaug.

ahmedmazari-dhatim avatar ahmedmazari-dhatim commented on May 22, 2024

@RomanSteinberg , where ?

from imgaug.

aleju avatar aleju commented on May 22, 2024

@ahmedmazari-dhatim change assert isinstance(image, list) to assert isinstance(images, list) (after the line def _augment_images(...)).
@RomanSteinberg rot90 will probably be included in the library (when I find the time).

from imgaug.

RomanSteinberg avatar RomanSteinberg commented on May 22, 2024

@aleju your implementation of _augment_keypoints seems to be incorrect. Because you trying to flip keypoints along the main diagonal. This is not equivalent to the rotation. So, the following code is my implementation.

def _augment_keypoints(self, keypoints_on_images, random_state, parents, hooks):
        nb_images = len(keypoints_on_images)
        samples = self.p.draw_samples((nb_images,), random_state=random_state)
        for i, keypoints_on_image in enumerate(keypoints_on_images):
            if samples[i] == 1:
                width, height = keypoints_on_image.shape[0:2]
                for keypoint in keypoints_on_image.keypoints:
                    keypoint.x, keypoint.y = keypoint.y, width - keypoint.x
                keypoints_on_image.shape = (height, width)
        return keypoints_on_images

from imgaug.

ahmedmazari-dhatim avatar ahmedmazari-dhatim commented on May 22, 2024

Thanks a lot

from imgaug.

BAILOOL avatar BAILOOL commented on May 22, 2024

@aleju Is this feature* available already in the library?
*Rotation by 90 degrees (shape (h,w) to (w,h))

from imgaug.

DNXie avatar DNXie commented on May 22, 2024

@aleju
Can the library let the users select the angle they want for rotating, not for default 45 degree. What if I only want my image to rotate 90, 180, 270 degree, how can I implement it?

from imgaug.

DNXie avatar DNXie commented on May 22, 2024

@aleju I think it helps! Thanks a lot!

from imgaug.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.