Skip to content

Commit cbf158b

Browse files
committed
Added fix (Replication contained deleted imports).
1 parent 38f9510 commit cbf158b

7 files changed

Lines changed: 7 additions & 78 deletions

File tree

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import duplipy
1+
import source
22
from .formatting import remove_stopwords, remove_numbers, remove_whitespace, normalize_whitespace, separate_symbols, remove_special_characters, standardize_text, tokenize_text, stem_words, lemmatize_words, pos_tag
3-
from .replication import replace_word_with_synonym, augment_text_with_synonyms, load_text_file, augment_file_with_synonyms, insert_random_word, delete_random_word, insert_synonym, paraphrase, flip_horizontal, flip_vertical, rotate, random_rotation, resize, crop, random_crop, perform_image_augmentation
3+
from .replication import replace_word_with_synonym, augment_text_with_synonyms, load_text_file, augment_file_with_synonyms, insert_random_word, delete_random_word, insert_synonym, paraphrase, flip_horizontal, flip_vertical, rotate, random_rotation, resize, crop, random_crop
44
from .similarity import edit_distance_score, bleu_score
55
from .text_analysis import analyze_sentiment
Lines changed: 1 addition & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@
1717
- `resize(image, size)`: Resize the input image to the specified size.
1818
- `crop(image, box)`: Crop the input image to the specified rectangular region.
1919
- `random_crop(image, size)`: Randomly crop a region from the input image.
20-
- `perform_image_augmentation(source_dir, target_dir, flip_horizontal=False, flip_vertical=False, rotate=False, random_rotation=False, resize=False, crop=False, max_angle=30, target_size=(224, 224), crop_size=(150, 150))`: Perform image augmentation on images in the source directory and its subdirectories.
2120
"""
2221

23-
import os
2422
import random
2523
import time
2624
import nltk
@@ -329,73 +327,4 @@ def random_crop(image, size):
329327
upper = random.randint(0, height - size[1])
330328
right = left + size[0]
331329
lower = upper + size[1]
332-
return crop(image, (left, upper, right, lower))
333-
334-
def perform_image_augmentation(
335-
source_dir,
336-
target_dir,
337-
flip_horizontal=False,
338-
flip_vertical=False,
339-
rotate=False,
340-
random_rotation=False,
341-
resize=False,
342-
crop=False,
343-
max_angle=30,
344-
target_size=(224, 224),
345-
crop_size=(150, 150)
346-
):
347-
"""
348-
Perform image augmentation on images in the source directory and its subdirectories.
349-
350-
Parameters:
351-
- `source_dir` (str): The path to the source directory containing the images.
352-
- `target_dir` (str): The path to the target directory where augmented images will be saved.
353-
- `flip_horizontal` (bool): Perform horizontal flipping if True. Default is False.
354-
- `flip_vertical` (bool): Perform vertical flipping if True. Default is False.
355-
- `rotate` (bool): Perform rotation if True. Default is False.
356-
- `random_rotation` (bool): Perform random rotation if True. Default is False.
357-
- `resize` (bool): Perform resizing if True. Default is False.
358-
- `crop` (bool): Perform cropping if True. Default is False.
359-
- `max_angle` (float): The maximum absolute angle of rotation in degrees. Default is 30.
360-
- `target_size` (tuple): The target size for resizing in the format (width, height). Default is (224, 224).
361-
- `crop_size` (tuple): The size of the cropped region in the format (width, height). Default is (150, 150).
362-
"""
363-
364-
def augment_image(image_path):
365-
image = Image.open(image_path)
366-
367-
if flip_horizontal and random.random() > 0.5:
368-
image = flip_horizontal(image)
369-
370-
if flip_vertical and random.random() > 0.5:
371-
image = flip_vertical(image)
372-
373-
if rotate and random.random() > 0.5:
374-
image = rotate(image, max_angle)
375-
376-
if random_rotation and random.random() > 0.5:
377-
image = random_rotation(image, max_angle)
378-
379-
if resize and random.random() > 0.5:
380-
image = resize(image, target_size)
381-
382-
if crop and random.random() > 0.5:
383-
image = random_crop(image, crop_size)
384-
385-
target_path = os.path.join(target_dir, os.path.relpath(image_path, source_dir))
386-
os.makedirs(os.path.dirname(target_path), exist_ok=True)
387-
image.save(target_path)
388-
389-
num_images = 0
390-
num_directories = 0
391-
392-
for root, _, files in os.walk(source_dir):
393-
num_directories += 1
394-
for file in files:
395-
if file.lower().endswith(('.jpg', '.jpeg', '.png', '.gif', '.bmp')):
396-
num_images += 1
397-
image_path = os.path.join(root, file)
398-
augment_image(image_path)
399-
print(f"Processed {num_images} images in {num_directories} directories.", end='\r')
400-
401-
print("\nImage augmentation completed successfully.")
330+
return crop(image, (left, upper, right, lower))

readme.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
# DupliPy 0.1.7
1+
# DupliPy 0.1.9
22

33
An open source Python library for text formatting, augmentation, and similarity calculation tasks in NLP.
44

5-
## Changes to DupliPy 0.1.7
5+
## Changes to DupliPy
66

77
DupliPy now offers support for image augmentation, with functions to rotate, resize and crop images. These are available through:
88
```python
9-
from duplipy.replication import flip_horizontal, flip_vertical, rotate, random_rotation, resize, crop, random_crop, perform_image_augmentation
9+
from duplipy.replication import flip_horizontal, flip_vertical, rotate, random_rotation, resize, crop, random_crop
1010
```
1111

1212
## Installation

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
setup(
44
name='duplipy',
5-
version='0.1.7',
5+
version='0.1.9',
66
author='Infinitode Pty Ltd',
77
author_email='infinitode.ltd@gmail.com',
88
description='A package for formatting and text replication, with added support for image augmentation.',

0 commit comments

Comments
 (0)