Comments (13)
not yet, its on the todo list
from imgaug.
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.
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.
Will you include this code in the library?
from imgaug.
@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.
l get the following error
It just a misspelling. It should be images
variable for sure.
from imgaug.
@RomanSteinberg , where ?
from imgaug.
@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.
@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.
Thanks a lot
from imgaug.
@aleju Is this feature* available already in the library?
*Rotation by 90 degrees (shape (h,w) to (w,h))
from imgaug.
@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.
@aleju I think it helps! Thanks a lot!
from imgaug.
Related Issues (20)
- Add distortion/fisheye effect
- Project dependencies may have API risk issues
- Is this project abandoned? HOT 8
- how to use imgaug to aug single image just one time?
- Out Of Memory (OOM) error in perspective transformation
- Support for Oriented Bouding Boxes
- AttributeError: module 'imgaug.augmenters' has no attribute 'LinearmnContrast' HOT 1
- numpy 1.20 bool deprecation HOT 1
- AttributeError: 'FigureCanvasAgg' object has no attribute 'set_window_title' HOT 2
- PIL version leads to immutable error
- It doesnt support latestversion of numpy HOT 2
- Track Random Augmentations as They Are Applied
- how to generate such image effect from clear images? I want to simulate scanner effects
- ImportError: cannot import name 'QhullError' from 'scipy.spatial' (/opt/conda/lib/python3.10/site-packages/scipy/spatial/__init__.py) HOT 3
- [BUG] show_grid and draw_grid are incompatible
- AttributeError: 'Delaunay' object has no attribute 'vertices'
- Affine transformation with warp mode doesn't "roll" keypoints
- "Fliplr" I am not sure what is wrong with this operation,
- "Fliplr", after applying this operation labels got disturbed
- Augment only parts of the image
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from imgaug.