Commit b973d4f1 authored by Josh's avatar Josh
Browse files

fixed slicing function

parent c348b083
......@@ -23,7 +23,6 @@ def sliceImage( imgArr: np.array, newSize: tuple ) -> dict:
returns: dictionary containing the following information
{
"slicedImages": [ ( xStartPos, yStartPos, slicedImgArr ) ],
"pixelsLost" : int,
"sliceCount" : int
}
OR empty dictionary if slicing was unable to be completed
......@@ -33,28 +32,28 @@ def sliceImage( imgArr: np.array, newSize: tuple ) -> dict:
newWidth = newSize[0]
newHeight = newSize[1]
# return empty dictionary if desired slice is larger than image
# Return empty dictionary if desired slice is larger than image
if newWidth > width or newHeight > height:
return {}
# all slices will be uniform, meaning
maxWidth = ( width // newWidth ) * newWidth
maxHeight = ( height // newHeight ) * newHeight
# return data
pixelsLost = ( width - maxWidth ) + ( height - maxHeight )
# Return data
newSliceCount = 0
imageList = []
# process image
for i in range( 0, maxWidth, newWidth ):
for j in range( 0, maxHeight, newHeight ):
# Process image
for i in range( 0, width, newWidth ):
for j in range( 0, height, newHeight ):
newSliceCount += 1
imageList.append( ( i, j, imgArr[i:i+newWidth, j:j+newHeight, :] ) )
# Create array of zeros of slice size
base = np.zeros( ( newWidth, newHeight, imgArr.shape[2] ) )
# Slice image and broadcase to base array
# Slice will be blacked out when outside range of original image
sliceArr = imgArr[i:i+newWidth, j:j+newHeight, :]
base[ :sliceArr.shape[0], :sliceArr.shape[1]] = sliceArr
imageList.append( ( i, j, base ) )
return {
"slicedImages": imageList,
"pixelsLost" : pixelsLost,
"sliceCount" : newSliceCount
}
......
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