Commit 05bd31fd authored by josh's avatar josh
Browse files

created distinct py program to run image sliceing

parent 580cf343
{
"python.linting.enabled": false
}
\ No newline at end of file
# ai4hdr_backend
## "sliceImage.py" program:
Slices an image into even sized tiles.
Note: if the slice size doesn't fit evenly into the size of
the original image, pixels will be lost.
## Command line arguments
- arg1: name of image file used for slicing
- arg2: file name used as base for all slices
- arg3: width of new slices
- arg4: height of new slices
- arg5: directory to save slices
## Example run
```bash
python sliceImage.py ../image_database/GeoEye_After011310.jpg base 512 512 ../image_database/
```
\ No newline at end of file
......@@ -8,14 +8,14 @@ def meanshiftSegmentation( image ):
pass
def sliceImage( imagePath: str, newFileBase: str, newSize: tuple, newPath: str=False ) -> int:
def sliceImage( imagePath: str, newFileBase: str, newSize: tuple, newPath: str ) -> int:
'''
Creates slices of images given
imagePath : path to image used for slicing
newFileBase: used to rename each slice
newSize : width and height of new slices
newPath : where to save new slices, cwd by default
newPath : where to save new slicest
returns: dictionary containing the following information
{
......@@ -25,14 +25,9 @@ def sliceImage( imagePath: str, newFileBase: str, newSize: tuple, newPath: str=F
}
OR empty dictionary if slicing was unable to be completed
'''
if not newPath:
newPath = pathlib.Path.cwd()
else:
newPath = pathlib.Path( newPath )
newPath = pathlib.Path( newPath )
image = cv2.imread( imagePath )
print( image.shape )
width = image.shape[0]
height = image.shape[1]
......@@ -66,12 +61,4 @@ def sliceImage( imagePath: str, newFileBase: str, newSize: tuple, newPath: str=F
"pixelsLost": pixelsLost,
"sliceCount": newSliceCount,
"slicePaths": newPaths
}
if __name__ == "__main__":
cwd = pathlib.Path.cwd()
imgPath = cwd.joinpath( "GeoEye_After011310.jpg" )
newFileBase = "GeoEye_Slice"
newPath = cwd.joinpath( "sliced_images" )
sliceImage( str( imgPath ), newFileBase, ( 512, 512 ), newPath=str( newPath ) )
\ No newline at end of file
}
\ No newline at end of file
import sys
from ai4hdr_utils import sliceImage
if __name__ == "__main__":
'''
Required arguments:
- arg1: image file used for slicing
- arg2: file name used as base for all slices
- arg3: width of new slices
- arg4: height of new slices
- arg5: directory to save slices
'''
if len( sys.argv ) == 6:
imagePath = sys.argv[1]
newFileBase = sys.argv[2]
newSize = ( int( sys.argv[3] ), int( sys.argv[4] ) )
newPath = sys.argv[5]
sliceImage( imagePath, newFileBase, newSize, newPath )
else:
print( "Invalid arg count" )
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment