Compare commits
No commits in common. "cc786484d71a1da91ae0abfc819a942b0ef19d73" and "55583b3afcb7739681dbc8fac1de81c678aeff95" have entirely different histories.
cc786484d7
...
55583b3afc
33
README.md
33
README.md
@ -37,41 +37,14 @@ pip install -r requirements.txt
|
|||||||
```
|
```
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
Run the script with the path to the image you want to split as an argument:
|
||||||
### As Windows Executable
|
|
||||||
You can run the program with either the path to a single image you want to split or a directory containing multiple images.
|
|
||||||
|
|
||||||
#### Single Image Mode
|
|
||||||
```sh
|
|
||||||
main.exe --image_path path_to_your_image.jpg
|
|
||||||
```
|
|
||||||
The program will create two new images in the "left" and "right" directories with the suffixes _left and _right added to the original file name.
|
|
||||||
|
|
||||||
#### Directory Mode
|
|
||||||
```sh
|
|
||||||
main.exe --directory path_to_your_directory
|
|
||||||
```
|
|
||||||
|
|
||||||
The program will iterate over all images in the directory, and for each image, it will create two new images in the "left" and "right" directories with the suffixes _left and _right added to the original file name.
|
|
||||||
|
|
||||||
### As a Python Script
|
|
||||||
You can run the script with either the path to a single image you want to split or a directory containing multiple images.
|
|
||||||
|
|
||||||
To split a single image:
|
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
python main.py --image_path path_to_your_image.jpg
|
python main.py path_to_your_image.jpg
|
||||||
```
|
```
|
||||||
|
|
||||||
The script will create two new images in the "left" and "right" directories with the suffixes _left and _right added to the original file name.
|
The script will create two new images in the "left" and "right" directories with the suffixes _left and _right added to the original file name.
|
||||||
|
|
||||||
To split all images in a directory:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
python main.py --directory path_to_your_directory
|
|
||||||
```
|
|
||||||
|
|
||||||
The script will iterate over all images in the directory, and for each image, it will create two new images in the "left" and "right" directories with the suffixes _left and _right added to the original file name.
|
|
||||||
|
|
||||||
## License
|
## License
|
||||||
This project is licensed under the terms of the MIT license.
|
This project is licensed under the terms of the MIT license.
|
||||||
|
|
||||||
|
27
main.py
27
main.py
@ -59,37 +59,14 @@ def split_image(image_path):
|
|||||||
img2.save(right_image_path)
|
img2.save(right_image_path)
|
||||||
|
|
||||||
|
|
||||||
def split_images_in_directory(directory):
|
|
||||||
# Get the list of files in the directory
|
|
||||||
files = os.listdir(directory)
|
|
||||||
|
|
||||||
# Filter the list to get only the image files
|
|
||||||
image_files = [f for f in files if f.endswith(".jpg") or f.endswith(".png")]
|
|
||||||
|
|
||||||
# Split each image
|
|
||||||
for image_file in image_files:
|
|
||||||
image_path = os.path.join(directory, image_file)
|
|
||||||
if not is_image_split(image_path):
|
|
||||||
split_image(image_path)
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(description="Split an image into two halves")
|
||||||
description="Split an image or all images in a directory into two halves"
|
parser.add_argument("image_path", help="Path to the image file")
|
||||||
)
|
|
||||||
parser.add_argument("--image_path", help="Path to the image file")
|
|
||||||
parser.add_argument("--directory", help="Path to the directory containing images")
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
if args.image_path:
|
|
||||||
if is_image_split(args.image_path):
|
if is_image_split(args.image_path):
|
||||||
print("The image is already split.")
|
print("The image is already split.")
|
||||||
else:
|
else:
|
||||||
split_image(args.image_path)
|
split_image(args.image_path)
|
||||||
elif args.directory:
|
|
||||||
split_images_in_directory(args.directory)
|
|
||||||
else:
|
|
||||||
print("Please provide either --image_path or --directory")
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
Loading…
x
Reference in New Issue
Block a user