Skip to content

Commit

Permalink
Updated up to the version 24.6
Browse files Browse the repository at this point in the history
  • Loading branch information
Evgeniy Sidenko committed Jun 5, 2024
1 parent 413826e commit c6c3351
Show file tree
Hide file tree
Showing 5 changed files with 196 additions and 3 deletions.
97 changes: 97 additions & 0 deletions Examples/src/modifyingandconvertingimages/KernelFilters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# GROUP: MODIFYING_AND_CONVERTING_IMAGES
import os, random
import aspose.pycore as aspycore
from aspose.imaging import Image, RasterImage, VectorImage
from aspose.imaging.imagefilters.complexutils import Complex
from aspose.imaging.imagefilters.convolution import *
from aspose.imaging.imagefilters.filteroptions import *


# Initialization
def get_data_root_dir_local():
if 'BASE_DIR' in os.environ:
return os.environ["BASE_DIR"]
return "."


if 'get_data_root_dir' not in dir():
get_data_root_dir = get_data_root_dir_local
if 'get_output_dir' not in dir():
get_output_dir = get_data_root_dir_local

delete_output = 'SAVE_OUTPUT' not in os.environ


def delete_file(file):
if delete_output:
os.remove(file)


# Example code:
def filter(raster, options, output_path):
raster.filter(raster.bounds, options)
raster.save(output_path)


def get_random_kernel(cols, rows):
custom_kernel = [0.0] * (cols * rows)
for y in range(rows):
for x in range(cols):
custom_kernel[y*cols + x] = random.random()

return custom_kernel


size: int = 5
sigma: float = 1.5
angle: float = 45
custom_kernel = get_random_kernel(size, 7)
custom_complex = ConvolutionFilter.to_complex(custom_kernel)
kernel_filters = [
# convolution filters
ConvolutionFilterOptions(ConvolutionFilter.get_emboss_3x3()),
ConvolutionFilterOptions(ConvolutionFilter.get_emboss_5x5()),
ConvolutionFilterOptions(ConvolutionFilter.get_sharpen_3x3()),
ConvolutionFilterOptions(ConvolutionFilter.get_sharpen_5x5()),
ConvolutionFilterOptions(ConvolutionFilter.get_blur_box(size)),
ConvolutionFilterOptions(ConvolutionFilter.get_blur_motion(size, angle)),
ConvolutionFilterOptions(ConvolutionFilter.get_gaussian(size, sigma)),
ConvolutionFilterOptions(custom_kernel),
GaussianBlurFilterOptions(size, sigma),
SharpenFilterOptions(size, sigma),
MedianFilterOptions(size),
# deconvolution filters
DeconvolutionFilterOptions(ConvolutionFilter.get_gaussian(size, sigma)),
DeconvolutionFilterOptions(custom_kernel),
DeconvolutionFilterOptions(custom_complex),
GaussWienerFilterOptions(size, sigma),
MotionWienerFilterOptions(size, sigma, angle)
]

data_dir = os.path.join(get_data_root_dir(), 'png')
input_paths = [
os.path.join(data_dir, "template.png")
]
outputs = []
for input_path in input_paths:
for i, options in enumerate(kernel_filters):
with Image.load(input_path) as image:
output_path = f"{input_path}-{i}.png"
if aspycore.is_assignable(image, RasterImage):
raster = aspycore.as_of(image, RasterImage)
filter(raster, options, output_path)
outputs.append(output_path)
elif aspycore.is_assignable(image, VectorImage):
vector = aspycore.as_of(image, VectorImage)
vector_as_png = input_path + ".png"
if not os.path.exists(vector_as_png):
vector.save(vector_as_png)
outputs.append(vector_as_png)

with Image.load(vector_as_png) as png:
filter(aspycore.as_of(png, RasterImage), options, output_path)
outputs.append(output_path)

# Removing all output files
for p in outputs:
delete_file(p)
37 changes: 37 additions & 0 deletions Examples/src/modifyingandconvertingimages/dicom/ModifyDicomTags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# GROUP: TEST_FILE_FORMATS
from aspose.pycore import as_of
from aspose.imaging.fileformats.dicom import DicomImage
from aspose.imaging import Image
import os


# Initialization
def get_data_root_dir_local():
if 'BASE_DIR' in os.environ:
return os.environ["BASE_DIR"]
return "."


if 'get_data_root_dir' not in dir():
get_data_root_dir = get_data_root_dir_local

if 'get_output_dir' not in dir():
get_output_dir = get_data_root_dir_local


# Example code:
print("Running example ModifyDicomTags")
# The path to the documents directory.
data_dir = os.path.join(get_data_root_dir(), 'dicom')
out_file = os.path.join(get_output_dir(), 'output.dcm')

with as_of(Image.load(dataDir + "file.dcm"), DicomImage) as image:
image.file_info.update_tag_at(33, "Test Patient") # "Patient's Name"
image.file_info.add_tag("Angular View Vector", 234)
image.file_info.remove_tag_at(29) # "Station Name"
image.save(out_file)

if 'SAVE_OUTPUT' not in os.environ:
os.remove(out_file)

print("Finished example ModifyDicomTags")
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# GROUP: MODIFYING_AND_CONVERTING_IMAGES
from aspose.pycore import as_of, is_assignable
from aspose.imaging.fileformats.dicom import DicomImage
from aspose.imaging import Image
from aspose.imaging.exif import IHasExifData
from aspose.imaging.imageoptions import DicomOptions
import os


# Initialization
def get_data_root_dir_local():
if 'BASE_DIR' in os.environ:
return os.environ["BASE_DIR"]
return "."


if 'get_data_root_dir' not in dir():
get_data_root_dir = get_data_root_dir_local

if 'get_output_dir' not in dir():
get_output_dir = get_data_root_dir_local


# Example code:

# The path to the documents directory.
data_dir = os.path.join(get_data_root_dir(), 'dicom')
out_file1 = os.path.join(get_output_dir(), 'output.dcm')
out_file2 = os.path.join(get_output_dir(), 'output_remove.dcm')
out_file3 = os.path.join(get_output_dir(), 'output_modify.dcm')

def exportWithMetadata(inputPath, outputPath, exportOptions):
with Image.load(inputPath) as image:
exportOptions.keep_metadata = True
image.save(outputPath, exportOptions)

def removeMetadata(inputPath, outputPath, exportOptions):
with Image.load(inputPath) as image:
image.remove_metadata()
image.save(outputPath, exportOptions)

def modifyMetada(inputPath, outputPath, exportOptions):
with Image.load(inputPath) as image:
if is_assignable(image, IHasExifData):
hasExif = as_of(image, IHasExifData)
if hasExif.exif_data is not None:
hasExif.exif_data.user_comment = f"Modified at {datetime.now()}"
exportOptions.keep_metadata = True

image.save(outputPath, exportOptions)

exportWithMetadata(os.path.join(data_dir, "file.dcm"), out_file1, DicomOptions())
removeMetadata(os.path.join(data_dir, "file.dcm"), out_file2, DicomOptions())
modifyMetada(os.path.join(data_dir, "file.dcm"), out_file3, DicomOptions())

if 'SAVE_OUTPUT' not in os.environ:
os.remove(out_file1)
os.remove(out_file2)
os.remove(out_file3)
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2001-2023 Aspose Pty Ltd
Copyright (c) 2001-2024 Aspose Pty Ltd

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# API for Image Processing

[Aspose.Imaging for Python via .NET](https://products.aspose.com/imaging/python-net) is a library offering advanced image processing features. Developers can create, edit or convert images in their own application. Also **Aspose.Imaging** library supports drawing and work with graphic primitives. Image exporting and conversion (including uniform multi-page image processing) is the one of API core features along with image transformations (resize, crop, flip&rotate, binarization, grayscale, adjust), advanced image manipulation features (filtering, dithering, masking, deskewing) and memory optimization strategies.
[Aspose.Imaging for Python via .NET](https://products.aspose.com/imaging/python-net) is Another Python Imaging Library offering advanced image processing features. Developers can create, edit or convert images in their own application. Also **Aspose.Imaging** library supports drawing and work with graphic primitives. Image exporting and conversion (including uniform multi-page image processing) is the one of API core features along with image transformations (resize, crop, flip&rotate, binarization, grayscale, adjust), advanced image manipulation features (filtering, dithering, masking, deskewing) and memory optimization strategies.

<p align="center">
<a title="Download ZIP" href="https://github.com/aspose-imaging/Aspose.Imaging-for-Python-NET/archive/main.zip">
Expand Down Expand Up @@ -45,7 +45,7 @@ Directory | Description

## Platform Independence

Aspose.Imaging for Python via .NET can be used to develop applications on Windows Desktop (x86, x64), Windows Server (x86, x64), Windows Azure, as well as Linux x64. Aspose.Imaging for Python is based on .NET Core 3.1 platform, so you need install it as well.
Aspose.Imaging for Python via .NET can be used to develop applications on Windows Desktop (x86, x64), Windows Server (x86, x64), Windows Azure, as well as Linux x64, macOS 10.14 (x86_64), and macOS 11.0 (arm64) . Aspose.Imaging for Python is based on .NET Core 6.0 platform, so you need install it as well.

## Get Started with Aspose.Imaging for Python via .NET

Expand Down

0 comments on commit c6c3351

Please sign in to comment.