def readImage(filename): if os.path.exists(filename): log.status("reading from " + filename) imageMemmap = array(Image.open(filename).convert("L")) log.status("successfully read from" + filename) try: os.remove(".temp.raw") finally: return imageMemmap else: log.error("can't read from " + filename) return None
def readImage(filename): if os.path.exists(filename): log.status("reading from " + filename) first = misc.imread(filename) first.tofile('.temp.raw') imageMemmap = np.memmap('.temp.raw', dtype=np.uint8, shape=first.shape) log.status("successfully read from" + filename) try: os.remove(".temp.raw") finally: return imageMemmap else: log.error("can't read from " + filename) return None
import time, argparse, imageIO, log from gauss import gaussian_blur from sobel import edge_detector from laplacian import sharpening parser = argparse.ArgumentParser() parser.add_argument('--blur', action='store_true') parser.add_argument('--edge', action='store_true') parser.add_argument('--sharp', action='store_true') parser.add_argument("input_file", help="The input image file.") parser.add_argument("output_file", help="The output image file.") args = parser.parse_args() img = imageIO.readImage(args.input_file) if img is not None: startTime = time.time() log.status("proccessing image") if args.blur: blurImage = gaussian_blur(img) imageIO.writeImage(blurImage, args.output_file) elif args.edge: edgeImage = edge_detector(img) imageIO.writeImage(edgeImage, args.output_file) elif args.sharp: sharpImage = sharpening(img) imageIO.writeImage(sharpImage, args.output_file)
def writeImage(imageMemmap,filename): log.status("writing image to "+filename) imageio.imwrite(filename, imageMemmap) log.status("image successfully write to " + filename)
def _statusDaemon(): while _enabled and threading.currentThread().getName() == _threadName: try: activeUsers, waitingUsers, isPaused = ezid.getStatus() na = sum(activeUsers.values()) nw = sum(waitingUsers.values()) ndo = datacite.numActiveOperations() uql = ezidapp.models.UpdateQueue.objects.count() bql = binder_async.getQueueLength() daql = datacite_async.getQueueLength() cqs = crossref.getQueueStatistics() doql = download.getQueueLength() as_ = search_util.numActiveSearches() no = log.getOperationCount() log.resetOperationCount() log.status("pid=%d" % os.getpid(), "threads=%d" % threading.activeCount(), "paused" if isPaused else "running", "activeOperations=%d%s" % (na, _formatUserCountList(activeUsers)), "waitingRequests=%d%s" % (nw, _formatUserCountList(waitingUsers)), "activeDataciteOperations=%d" % ndo, "updateQueueLength=%d" % uql, "binderQueueLength=%d" % bql, "dataciteQueueLength=%d" % daql, "crossrefQueue:archived/unsubmitted/submitted=%d/%d/%d" %\ (cqs[2]+cqs[3], cqs[0], cqs[1]), "downloadQueueLength=%d" % doql, "activeSearches=%d" % as_, "operationCount=%d" % no) if _cloudwatchEnabled: import boto3 # Disable annoying boto3 logging. logging.getLogger("botocore").setLevel(logging.ERROR) try: c = boto3.client("cloudwatch", region_name=_cloudwatchRegion) d = [{ "Name": "InstanceName", "Value": _cloudwatchInstanceName }] data = { "ActiveOperations": na, "WaitingRequests": nw, "ActiveDataciteOperations": ndo, "UpdateQueueLength": uql, "BinderQueueLength": bql, "DataciteQueueLength": daql, "CrossrefQueueLength": cqs[0] + cqs[1], "DownloadQueueLength": doql, "ActiveSearches": as_, "OperationRate": float(no) / _reportingInterval } r = c.put_metric_data(Namespace=_cloudwatchNamespace, MetricData=[{ "MetricName": k, "Dimensions": d, "Value": float(v), "Unit": "Count/Second" if k == "OperationRate" else "Count" }\ for k, v in data.items()]) assert r["ResponseMetadata"]["HTTPStatusCode"] == 200 except: # Ignore CloudWatch exceptions, as it's not essential. pass except Exception, e: log.otherError("status._statusDaemon", e) django.db.connections["default"].close() time.sleep(_reportingInterval)
parser.add_argument('--grayscale', action='store_true') parser.add_argument('--edge', action='store_true') parser.add_argument('--color_filter', action='store_true') parser.add_argument('--color', help='red,green,blue,brown', type=str, default="red") parser.add_argument("input_file", help="The input image file.") parser.add_argument("output_file", help="The output image file.") args = parser.parse_args() img = imageIO.readImage(args.input_file) if img is not None: startTime = time.time() log.status("proccessing image") if args.blur: blurImage = blur(img, args.sigma) imageIO.writeImage(blurImage, args.output_file) elif args.edge: edgeImage = edgeDetection(img) imageIO.writeImage(edgeImage, args.output_file) elif args.invert_colors: invertImage = basicFilters.invertColors(img) imageIO.writeImage(invertImage, args.output_file) elif args.grayscale: grayscaleImage = basicFilters.grayscaleFilter(img) imageIO.writeImage(grayscaleImage, args.output_file) elif args.color_filter: color = colors.getColor(args.color) if color is not None: