Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for Py3 and Newer numpy #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ Heavily adapted from [this StackOverflow answer][so] by [fraxel][fr] and [this c

halftone.py [-h] [-a ANGLES [ANGLES ...]] [-b {1,2,4,6,8}] [-c] [-d]
[-e EXTRA_FILE_NAME] [-f FILL] [-g GRAY] [-p SHARPNESS]
[-s SIZE]
[-s SIZE] [-l]
file

Creates four CMYK images and a combined image. Provides options for haltoning or not (-d)

| OPTION | DESCRIPTION | Default |
| ---------------------- | ----------------------------------------------- | ------- |
| -h, --help | show this help message and exit | n/a |
| -l, --halftone | halftone the image | False |
| -b, --bits {1,2,4,6,8} | bits of color info per channel | 8 |
| -c, --colorize_CMYK | save CMYK files as RGB color images | False |
| -d, --do_not_halftone | don't do halftoning | False |
Expand Down
2 changes: 1 addition & 1 deletion TiffWriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def write_tiff(file_name, img, bit_depth=8, photometric=None, DPI=200):
Affects: Writes over existing files without warning
"""

print file_name
print(file_name)

if len(img.shape) == 1:
height = 1
Expand Down
13 changes: 8 additions & 5 deletions halftone.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/env python

from PIL import Image
import numpy as np
from scipy.ndimage.interpolation import rotate
Expand All @@ -20,7 +18,8 @@ def crop_center(img, new_shape):
"""
ul = ((img.shape[0]-new_shape[0])/2, (img.shape[1]-new_shape[1])/2)
br = (ul[0]+new_shape[0], ul[1]+new_shape[1])
return img[ul[0]:br[0], ul[1]:br[1]]
#print(f"ul[0]= {ul[0]} : br[0]= {br[0]}, ul[1]= {ul[1]}: br[1]= {br[1]}")
return img[int(ul[0]):int(br[0]), int(ul[1]):int(br[1])]


def gauss_kernel(size, sigma=None, size_y=None, sigma_y=None):
Expand Down Expand Up @@ -108,7 +107,10 @@ def halftone(cmyk, size, angles, fill, sharpness):

# tile the kernel across the image
num_kernels = np.array(rotated.shape) / s + 1
tiled_kernel = np.tile(kernel, num_kernels)
# print(f"kernel: {kernel} - num_kernels: {num_kernels}")
# print(f"kernel: {type(kernel)} - num_kernels: {type(num_kernels)}")
# print(num_kernels[1])
tiled_kernel = np.tile(kernel, (int(num_kernels[0]), int(num_kernels[1])))
tiled_kernel = resize(tiled_kernel, rotated.shape)

# multiply the kernel image with the weights to generate the halftone image
Expand All @@ -118,6 +120,7 @@ def halftone(cmyk, size, angles, fill, sharpness):
halftone = rotate(halftone, -angle, prefilter=False, order=1)

# crop the image to the original size
#print(f"channel.shape: {channel.shape}")
halftone = crop_center(halftone, channel.shape)

# add this chanel to the full cmyk image
Expand Down Expand Up @@ -205,7 +208,7 @@ def test():
try:
im = Image.open(args.file)
except IOError:
print "Cannot open ", args.file
print("Cannot open ", args.file)
exit(1)

# convert to numpy array
Expand Down