-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* resolves issue #19 and #18 * rotates mask * takes away spurious 'f' characters in argparse file * corrected formating (converted from f-string to other string format) * Fix syntax warning (#22) * Modularity changes * Some small formatting fixes * Packaged code * Packaged code * Some cleanup * Import tweak * More updates and fixes * More fixes * Updated README.md * Caught up to master * Fixed packaging issues, some general cleanup * Formatting fixes * Fixed accidental requirements change * Forgot these files * Fix cropping bug * Fixed sorting randomness bug * Fixed release version
- Loading branch information
1 parent
1f41ed7
commit 8333e34
Showing
14 changed files
with
311 additions
and
257 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from pixelsort.main import pixelsort | ||
NAME = "pixelsort" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from PIL import Image | ||
import logging | ||
from pixelsort.argparams import parse_args | ||
from pixelsort.main import pixelsort | ||
from pixelsort.util import id_generator | ||
|
||
args = parse_args() | ||
image_input_path = args.pop("image_input_path") | ||
image_output_path = args.pop("image_output_path") | ||
interval_file_path = args.pop("interval_file_path") | ||
mask_path = args.pop("mask_path") | ||
|
||
if image_output_path is None: | ||
image_output_path = id_generator() + ".png" | ||
logging.warning("No output path provided, using " + image_output_path) | ||
|
||
logging.debug("Opening image...") | ||
args["image"] = Image.open(image_input_path) | ||
if mask_path: | ||
logging.debug("Opening mask...") | ||
args["mask_image"] = Image.open(mask_path) | ||
if interval_file_path: | ||
logging.debug("Opening interval file...") | ||
args["interval_file"] = Image.open(interval_file_path) | ||
|
||
logging.debug("Saving image...") | ||
pixelsort(**args).save(image_output_path) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import argparse | ||
import logging | ||
from pixelsort.interval import choices as interval_choices | ||
from pixelsort.sorting import choices as sorting_choices | ||
from pixelsort.constants import DEFAULTS | ||
|
||
|
||
def parse_args(): | ||
parser = argparse.ArgumentParser(description="Pixel mangle an image.") | ||
parser.add_argument("image", help="Input image file path.") | ||
parser.add_argument("-o", "--output", | ||
help="Output image file path, DEFAULTS to the time created.") | ||
parser.add_argument("-i", "--int_function", | ||
choices=interval_choices.keys(), | ||
default=DEFAULTS["interval_function"], | ||
help="Function to determine sorting intervals") | ||
parser.add_argument("-f", "--int_file", | ||
help="Image used for defining intervals.") | ||
parser.add_argument("-t", "--threshold", type=float, default=DEFAULTS["lower_threshold"], | ||
help="Pixels darker than this are not sorted, between 0 and 1") | ||
parser.add_argument("-u", "--upper_threshold", type=float, default=DEFAULTS["upper_threshold"], | ||
help="Pixels brighter than this are not sorted, between 0 and 1") | ||
parser.add_argument("-c", "--clength", type=int, default=DEFAULTS["clength"], | ||
help="Characteristic length of random intervals") | ||
parser.add_argument("-a", "--angle", type=float, default=DEFAULTS["angle"], | ||
help="Rotate the image by an angle (in degrees) before sorting") | ||
parser.add_argument("-r", "--randomness", type=float, default=DEFAULTS["randomness"], | ||
help="What percentage of intervals are NOT sorted") | ||
parser.add_argument("-s", "--sorting_function", | ||
choices=sorting_choices.keys(), | ||
default=DEFAULTS["sorting_function"], | ||
help="Function to sort pixels by.") | ||
parser.add_argument( | ||
"-m", "--mask", help="Image used for masking parts of the image") | ||
parser.add_argument("-l", "--log_level", default="WARNING", help="Print more or less info", | ||
choices=["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"]) | ||
|
||
_args = parser.parse_args() | ||
|
||
logging.basicConfig( | ||
format="%(name)s: %(levelname)s - %(message)s", level=logging.getLevelName(_args.log_level)) | ||
|
||
return { | ||
"image_input_path": _args.image, | ||
"image_output_path": _args.output, | ||
"interval_function": _args.int_function, | ||
"interval_file_path": _args.int_file, | ||
"lower_threshold": _args.threshold, | ||
"upper_threshold": _args.upper_threshold, | ||
"clength": _args.clength, | ||
"angle": _args.angle, | ||
"randomness": _args.randomness, | ||
"sorting_function": _args.sorting_function, | ||
"mask_path": _args.mask | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
BLACK_PIXEL = (0, 0, 0, 255) | ||
WHITE_PIXEL = (255, 255, 255, 255) | ||
DEFAULTS = { | ||
"interval_function": "threshold", | ||
"lower_threshold": 0.25, | ||
"upper_threshold": 0.8, | ||
"clength": 50, | ||
"angle": 0, | ||
"randomness": 0, | ||
"sorting_function": "lightness", | ||
} |
Oops, something went wrong.