Commit 98361753 authored by josh's avatar josh
Browse files

pymeanshift implemented and program added

parent df68d081
{
"cells": [],
"metadata": {},
"nbformat": 4,
"nbformat_minor": 4
}
......@@ -33,7 +33,36 @@ python sliceImage.py ./sliceImageResults/GeoEye_Original.jpg GeoEye_Slice 512 51
## Slice 4: 512x512
![](sliceImageResults/GeoEye_Slice-512-512.jpg)
## "meanShift.py" program:
## "meanShiftSeg.py" program:
Uses the pymeanshift library to create a segmented images
Install pymeanshift: pip install git+git://github.com/fjean/pymeanshift.git
## Command line arguments:
- arg1: image file used for segmentation
- arg2: directory to save results
- arg3: base name for results files
- arg4: spatial radius for ms algo
- arg5: range radius for ms algo
- arg6: min density for ms algo
## Example run:
```bash
python meanShiftSeg.py ./meanShiftResults/GeoEye_MS_Original.jpg ./meanShiftResults/ pyms 6 6 50
```
## Example run result:
## Original Image:
![](meanShiftResults/GeoEye_MS_Original.jpg)
## Segmentation Image:
![](meanShiftResults/pyms-color-seg.jpg)
## Labels Image:
![](meanShiftResults/pyms-labels-image.jpg)
## "meanShift3Channel.py" program:
Uses the mean shift algorithm to create a segmentation mask for an image.
## Command line arguments:
......@@ -42,7 +71,7 @@ Uses the mean shift algorithm to create a segmentation mask for an image.
## Example run:
```bash
python meanShift.py meanShiftResults/GeoEye_MS_Original.jpg meanShiftResults/GeoEye_MS_Segmented
python meanShift3Channel.py meanShiftResults/GeoEye_MS_Original.jpg meanShiftResults/GeoEye_MS_Segmented
```
## Example run result:
......@@ -50,7 +79,9 @@ python meanShift.py meanShiftResults/GeoEye_MS_Original.jpg meanShiftResults/Geo
![](meanShiftResults/GeoEye_MS_Original.jpg)
## Segmentation Image:
![](meanShiftResults/GeoEye_MS_Segmented.jpg)
![](meanShiftResults/three_channel_seg.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
This program takes roughly 20 seconds to run, tested on an AMD FX(tm)-4300 Quad-Core Processor
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import pymeanshift as pms\n",
"import cv2\n",
"import matplotlib.pyplot as plt"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [],
"source": [
"imagePath = \"redBall.jpeg\"\n",
"original_image = cv2.imread( imagePath )"
]
},
{
"cell_type": "code",
"execution_count": 47,
"metadata": {},
"outputs": [],
"source": [
"(segmented_image, labels_image, number_regions) = pms.segment(original_image, spatial_radius=10, \n",
" range_radius=10, min_density=200)"
]
},
{
"cell_type": "code",
"execution_count": 48,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<matplotlib.image.AxesImage at 0x7f1e4b60f978>"
]
},
"execution_count": 48,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAQgAAAD8CAYAAACLgjpEAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAXlklEQVR4nO3df7BdZX3v8fcniaBSJSGEEJMgoebWQb2teAbwekcYiPwqNWRKK5Yp0aYT76312nJnNFyn49zbf/S2o9WZVk0FGzoRsAiSy+jE8MN6ZzqkSfwBAYQcYzXJTchBQ3RAhdjv/WM9O9nnZK9zzv619vrxec3sOWs9a539rHXWsz/neZ69z1mKCMzMOpkz6gMws/JyQJhZLgeEmeVyQJhZLgeEmeVyQJhZrsIDQtJVkp6SNC5pQ9H1m9nsqcjPQUiaCzwNvAPYD+wA3h0RTxR2EGY2a0X3IC4ExiNib0S8CNwJrC74GMxsluYVXN9SYF/b+n7govYdJK0H1gOcdtppb3n9619f3NGZNdCuXbuejYhFnbYVHRAzioiNwEaAsbGx2LFj54iPyKze5szRD/O2FR0QB4DlbevLUpmV3KpLNg/8OR/45xsH/pw2WEUHxA5gpaQVZMFwA/AHBR+D5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ASUVORK5CYII=\n",
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"plt.imshow( segmented_image )"
]
},
{
"cell_type": "code",
"execution_count": 49,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"<class 'numpy.ndarray'>\n",
"<class 'numpy.ndarray'>\n",
"<class 'int'>\n"
]
}
],
"source": [
"print( type( segmented_image ) )\n",
"print( type( labels_image ) )\n",
"print( type( number_regions ) )"
]
},
{
"cell_type": "code",
"execution_count": 50,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<matplotlib.image.AxesImage at 0x7f1e4b7752b0>"
]
},
"execution_count": 50,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAQgAAAD8CAYAAACLgjpEAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAXXklEQVR4nO3de7Bd5V3/8ffHE5JISy4ndfilJ9EcbCzipRIzhE79adtUbu0QnKlMsLVpRTP9/ehPBGdqsH909PePtU6RzlQwFTS1FIqxSqaiyK3V/kFsUhQIJORIKElMGu5gMwFCv/6xnnOyc7LXuezL2uvyec3sOWs9a539rHXWsz/neZ69z1mKCMzM2vmhQR+AmZWXA8LMcjkgzCyXA8LMcjkgzCyXA8LMchUeEJIukrRH0pikTUXXb2YzpyI/ByFpCHgC+GXgAPBt4IqIeKywgzCzGSu6B3EeMBYRT0bEa8DtwLqCj8HMZmhOwfWNAPtb1g8Aa1p3kLQR2AgwxNDPn86C4o7OrIFe4YVnI+JH2m0rOiCmFRGbgc0ACzQca7R2wEdkVm/3xtbv5m0rOiAOAstb1pelMiu5oSXDPX/ON557vufPab1VdEB8G1gpaZQsGNYDv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/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"plt.imshow( labels_image )"
]
},
{
"cell_type": "code",
"execution_count": 51,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[[0 0 0 ... 0 0 0]\n",
" [0 0 0 ... 0 0 0]\n",
" [0 0 0 ... 0 0 0]\n",
" ...\n",
" [0 0 0 ... 0 0 0]\n",
" [0 0 0 ... 0 0 0]\n",
" [0 0 0 ... 0 0 0]]\n",
"(1400, 1400)\n"
]
}
],
"source": [
"print( labels_image )\n",
"print( labels_image.shape )"
]
},
{
"cell_type": "code",
"execution_count": 52,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"19"
]
},
"execution_count": 52,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"labels_image.max()"
]
},
{
"cell_type": "code",
"execution_count": 53,
"metadata": {},
"outputs": [],
"source": [
"newLabelsImage = labels_image / labels_image.max()"
]
},
{
"cell_type": "code",
"execution_count": 54,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1.0"
]
},
"execution_count": 54,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"newLabelsImage.max()"
]
},
{
"cell_type": "code",
"execution_count": 55,
"metadata": {},
"outputs": [],
"source": [
"newLabelsImage *= 255"
]
},
{
"cell_type": "code",
"execution_count": 56,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"255.0"
]
},
"execution_count": 56,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"newLabelsImage.max()"
]
},
{
"cell_type": "code",
"execution_count": 57,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 57,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAQgAAAD8CAYAAACLgjpEAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29m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JQuMIs77fcC+iHgmIl4Hvkb2syjivMfN9jx72hYlfRT4APChFFCF1d2JsgbEt4GVaXZ7LtkE1bZeViBJwM3A4xHxuZZN24DxmeoNZHMT4+UfSbPd5wMvtXRVZyUirouIZRGxguzc7o+IDwEPAB/MqXv8mD6Y9u/oN19EHAb2S3p7KloLPEYB5002tDhf0unp5z9ed9/Pu8Vsz/Nu4AJJi1MP6IJUNmuSLiIbVl4aEUcnHdP69K7NKLAS+DcKeB1Mq8gJj9k8yGaVnyCbxf1UH57/F8i6lw8D/54el5CNce8D9gL3AsNpfwFfSMfzCLC6R8fxbk68i3EWWcMYA/4GmJfK56f1sbT9rC7r/DlgRzr3vyebnS/kvIE/AHYDjwJ/TTZz35fzBm4jm+t4nazndGUn50k2XzCWHh/rou4xsjmF8fZ2U8v+n0p17wEuLup1MN3DH7U2s1xlHWKYWQk4IMwslwPCzHI5IMwslwPCzHI5IMwslwPCzHL9D9tT9XK4esSgAAAAAElFTkSuQmCC\n",
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"plt.imshow( newLabelsImage )\n",
"cv2.imwrite( \"test.png\", newLabelsImage )"
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"np.savetxt(\"labels.csv\", labels_image, delimiter=\",\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "gpu_tf",
"language": "python",
"name": "gpu_tf"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.9"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
import cv2
import pathlib
import numpy as np
import os
import matplotlib.pyplot as plt
import matplotlib.colors as mcolors
import pymeanshift as pms
from matplotlib.colors import to_rgb
from sklearn.cluster import MeanShift, estimate_bandwidth
from skimage import color
def sliceImage( imagePath: str, newFileBase: str, newSize: tuple, newPath: str ) -> dict:
def sliceImage( imagePath: str, newSize: tuple ) -> dict:
'''
Creates slices of an image.
Parameters:
- 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 slicest
returns: dictionary containing the following information
{
"pixelsLost": int,
"sliceCount": int,
"slicePaths": list
"slicedImages": [ ( xStartPos, yStartPos, imgArr ) ],
"pixelsLost" : int,
"sliceCount" : int
}
OR empty dictionary if slicing was unable to be completed
'''
fileExt = pathlib.Path( imagePath ).name.split( "." )[-1]
newPath = pathlib.Path( newPath )
image = cv2.imread( imagePath )
......@@ -47,25 +46,22 @@ def sliceImage( imagePath: str, newFileBase: str, newSize: tuple, newPath: str )
# return data
pixelsLost = ( width - maxWidth ) + ( height - maxHeight )
newSliceCount = 0
newPaths = []
imageList = []
# process image
for i in range( 0, maxWidth, newWidth ):
for j in range( 0, maxHeight, newHeight ):
slicePath = newPath.joinpath( "{}-{}-{}.{}".format( newFileBase, i, j, fileExt ) )
newSliceCount += 1
newPaths.append( slicePath )
cv2.imwrite( str( slicePath ),
image[i:i+newWidth, j:j+newHeight, :] )
imageList.append( ( i, j, image[i:i+newWidth, j:j+newHeight, :] ) )
return {
"pixelsLost": pixelsLost,
"sliceCount": newSliceCount,
"slicePaths": newPaths
"slicedImages": imageList,
"pixelsLost" : pixelsLost,
"sliceCount" : newSliceCount
}
def meanshiftSegmentation( imagePath: str, outPath: str, quantile=0.2, samples=500, classColors: list=None ) -> dict:
def meanshift3Channel( imagePath: str, outPath: str, quantile=0.2, samples=500, classColors: list=None ) -> dict:
'''
SOURCE: https://www.efavdb.com/mean-shift
......@@ -87,7 +83,6 @@ def meanshiftSegmentation( imagePath: str, outPath: str, quantile=0.2, samples=5
2: ( "gold", ( 1.0, 0.8, 0.0 ) )
}
Quantile and samples are used for sklearn estimate_bandwidth function.
For more info: https://scikit-learn.org/stable/modules/generated/sklearn.cluster.estimate_bandwidth.html
'''
......@@ -140,4 +135,69 @@ def meanshiftSegmentation( imagePath: str, outPath: str, quantile=0.2, samples=5
1: ( classColors[1], color2 ),
2: ( classColors[2], color3 )
}
\ No newline at end of file
def meanShiftSegmentation( imagePath: str, outPath: str, spatialRadius: int=6, rangeRadius: int=6, minDensity: int=50 ):
'''
SOURCE - https://github.com/fjean/pymeanshift
return: ( segmented_image, labels_image, number_regions )
'''
original_image = cv2.imread( imagePath )
return pms.segment( original_image,
spatial_radius=spatialRadius,
range_radius=rangeRadius,
min_density=minDensity )
'''
Database functions
Database file structure example:
|-- ImageDatabase
│   |-- MeanShift
| | |--image_name-id
| | | |--128x128
| | | | |--image_name-128-smap-0-0.<ext> <- segmented map
| | | | |--image_name-128-simage-0-0.<ext> <- segmented image
| | | |--256x256
| | | |--512x512
│   |-- Original
| | |--image_name-id.<ext> <- original image, id = auto increment integer
│   |-- Sliced
| | |--image_name-id
| | | |--128x128
| | | | |--image_name-128-0-0.<ext> <- sliced image
| | | |--256x256
| | | |--512x512
'''
def initDB( baseDir: str, name: str ) -> bool:
'''
Initialized the image database at a given directory
File Struture:
|-- ImageDatabase
│   |-- MeanShift
│   |-- Original
│   |-- Sliced
'''
baseDir = pathlib.Path( baseDir )
dbDir = baseDir.joinpath( name )
if dbDir.is_dir():
print( "Failed to init: a database with this name already exists." )
return False
else:
originalImagesDir = dbDir.joinpath( "Original" )
slicedImagesDir = dbDir.joinpath( "Sliced" )
meanShiftSegDir = dbDir.joinpath( "MeanShift" )
os.mkdir( dbDir )
os.mkdir( originalImagesDir )
os.mkdir( slicedImagesDir )
os.mkdir( meanShiftSegDir )
if __name__ == "__main__":
baseDir = "../"
initDB( baseDir, "ImageDatabase" )
\ No newline at end of file
import sys
from ai4hdr_utils import meanshiftSegmentation
from ai4hdr_utils import meanshift3Channel
if __name__ == "__main__":
'''
......@@ -19,11 +19,11 @@ if __name__ == "__main__":
samples = 500
classColors = [ "darkgreen", "indigo", "gold" ]
result = meanshiftSegmentation( imagePath=imagePath,
outPath=outPath,
quantile=quantile,
samples=samples,
classColors=classColors )
result = meanshift3Channel( imagePath=imagePath,
outPath=outPath,
quantile=quantile,
samples=samples,
classColors=classColors )
else:
print( "Invalid arg count" )
......
import sys
import pathlib
import cv2
import numpy as np
from ai4hdr_utils import meanShiftSegmentation
if __name__ == "__main__":
'''
Required arguments:
- arg1: image file used for segmentation
- arg2: directory to save results
- arg3: base name for results files
- arg4: spatial radius for ms algo
- arg5: range radius for ms algo
- arg6: min density for ms algo
'''
if len( sys.argv ) == 7:
imagePath = sys.argv[1]
outPath = pathlib.Path( sys.argv[2] )
baseFileName = sys.argv[3]
spatialRadius = int( sys.argv[4] )
rangeRadius = int( sys.argv[5] )
minDensity = int( sys.argv[6] )
( segmentedImage, labelsImage, numberRegions ) = meanShiftSegmentation( imagePath=imagePath,
outPath=outPath,
spatialRadius=spatialRadius,
rangeRadius=rangeRadius,
minDensity=minDensity )
fileExt = pathlib.Path( imagePath ).name.split( "." )[-1]
segColorPath = outPath.joinpath( "{}-color-seg.{}".format( baseFileName, fileExt ) )
labelImgPath = outPath.joinpath( "{}-labels-image.{}".format( baseFileName, fileExt ) )
# scale labelsImage to [0,255]
print( labelsImage.max() )
labelsImage = labelsImage.astype( float )
labelsImage /= labelsImage.max()
labelsImage *= 255
# save results to image files
cv2.imwrite( str( segColorPath ), segmentedImage )
cv2.imwrite( str( labelImgPath ), labelsImage )
else:
print( "Invalid arg count" )
\ No newline at end of file
import sys
import cv2
import pathlib
from ai4hdr_utils import sliceImage
......@@ -17,7 +19,21 @@ if __name__ == "__main__":
newFileBase = sys.argv[2]
newSize = ( int( sys.argv[3] ), int( sys.argv[4] ) )
newPath = sys.argv[5]
sliceImage( imagePath, newFileBase, newSize, newPath )
# get sliced images
result = sliceImage( imagePath, newSize )
fileExt = pathlib.Path( imagePath ).name.split( "." )[-1]
newPath = pathlib.Path( newPath )
# save each image to DB
for res in result["slicedImages"]:
i = res[0]
j = res[1]
imgArr = res[2]
slicePath = newPath.joinpath( "{}-{}-{}.{}".format( newFileBase, i, j, fileExt ) )
cv2.imwrite( str( slicePath ), imgArr )
else:
print( "Invalid arg count" )
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