Commit df68d081 authored by josh's avatar josh
Browse files

created separate prog to run meanshift from terminal, added to readme the results of meanshift

parent 7840e5a4
......@@ -5,30 +5,52 @@ 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
## 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 ./sliceImage_ex/GeoEye_After011310.jpg GeoEye_Slice 512 512 ./sliceImage_ex/
python sliceImage.py ./sliceImageResults/GeoEye_Original.jpg GeoEye_Slice 512 512 ./sliceImageResults/
```
## Example run result
## Example run result:
## Original Image: 1180x1180
![](sliceImage_ex/GeoEye_After011310.jpg)
![](sliceImageResults/GeoEye_Original.jpg)
## Slice 1: 512x512
![](sliceImage_ex/GeoEye_Slice-0-0.jpg)
![](sliceImageResults/GeoEye_Slice-0-0.jpg)
## Slice 2: 512x512
![](sliceImage_ex/GeoEye_Slice-0-512.jpg)
![](sliceImageResults/GeoEye_Slice-0-512.jpg)
## Slice 3: 512x512
![](sliceImage_ex/GeoEye_Slice-512-0.jpg)
![](sliceImageResults/GeoEye_Slice-512-0.jpg)
## Slice 4: 512x512
![](sliceImage_ex/GeoEye_Slice-512-512.jpg)
\ No newline at end of file
![](sliceImageResults/GeoEye_Slice-512-512.jpg)
## "meanShift.py" program:
Uses the mean shift algorithm to create a segmentation mask for an image.
## Command line arguments:
- arg1: image file used for segmentation
- arg2: file name to save segmentation
## Example run:
```bash
python meanShift.py meanShiftResults/GeoEye_MS_Original.jpg meanShiftResults/GeoEye_MS_Segmented
```
## Example run result:
## Original Image:
![](meanShiftResults/GeoEye_MS_Original.jpg)
## Segmentation Image:
![](meanShiftResults/GeoEye_MS_Segmented.jpg)
## Program run time:
This program takes roughly 20 seconds to run, tested on an AMD FX(tm)-4300 Quad-Core Processor
\ No newline at end of file
......@@ -65,7 +65,7 @@ def sliceImage( imagePath: str, newFileBase: str, newSize: tuple, newPath: str )
}
def meanshiftSegmentation( imagePath: str, outPath: str, classColors: list=None, quantile=0.2, samples=500 ) -> dict:
def meanshiftSegmentation( imagePath: str, outPath: str, quantile=0.2, samples=500, classColors: list=None ) -> dict:
'''
SOURCE: https://www.efavdb.com/mean-shift
......@@ -75,10 +75,10 @@ def meanshiftSegmentation( imagePath: str, outPath: str, classColors: list=None,
Parameters:
- imagePath : path to image used
- outPath : path to save segmented image ( image type extension automatically added )
- classColors : custom list of colors to use for classes, default: [ "darkgreen", "indigo", "gold" ]
Note: list index = class label
- quantile : used for estimate_bandwidth function, should be between [0, 1], default: 0.2
- samples : used for estimate_bandwidth function, number of samples to use, defualt: 500
- classColors : custom list of colors to use for classes, default: [ "darkgreen", "indigo", "gold" ]
Note: list index = class label
Returns: a dictionary mapping the class integer to a tuple containing a color name and rgb value
{
......@@ -140,11 +140,4 @@ def meanshiftSegmentation( imagePath: str, outPath: str, classColors: list=None,
1: ( classColors[1], color2 ),
2: ( classColors[2], color3 )
}
if __name__ == "__main__":
cwd = pathlib.Path.cwd()
imagePath = cwd.joinpath( "meanShiftSeg_ex/GeoEye_MS_Original.jpg" )
outPath = cwd.joinpath( "meanShiftSeg_ex/GeoEye_MS_Segmented" )
result = meanshiftSegmentation( str( imagePath ), str( outPath ) )
\ No newline at end of file
\ No newline at end of file
import sys
from ai4hdr_utils import meanshiftSegmentation
if __name__ == "__main__":
'''
Required arguments:
- arg1: image file used for segmentation
- arg2: file name to save segmentation
'''
if len( sys.argv ) == 3:
imagePath = sys.argv[1]
outPath = sys.argv[2]
'''
TO DO: Need customization of following parameters?
For now, using same defaults as the function
'''
quantile = 0.2
samples = 500
classColors = [ "darkgreen", "indigo", "gold" ]
result = meanshiftSegmentation( imagePath=imagePath,
outPath=outPath,
quantile=quantile,
samples=samples,
classColors=classColors )
else:
print( "Invalid arg count" )
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
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