Skip to content

Commit c6c3351

Browse files
author
Evgeniy Sidenko
committed
Updated up to the version 24.6
1 parent 413826e commit c6c3351

File tree

5 files changed

+196
-3
lines changed

5 files changed

+196
-3
lines changed
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# GROUP: MODIFYING_AND_CONVERTING_IMAGES
2+
import os, random
3+
import aspose.pycore as aspycore
4+
from aspose.imaging import Image, RasterImage, VectorImage
5+
from aspose.imaging.imagefilters.complexutils import Complex
6+
from aspose.imaging.imagefilters.convolution import *
7+
from aspose.imaging.imagefilters.filteroptions import *
8+
9+
10+
# Initialization
11+
def get_data_root_dir_local():
12+
if 'BASE_DIR' in os.environ:
13+
return os.environ["BASE_DIR"]
14+
return "."
15+
16+
17+
if 'get_data_root_dir' not in dir():
18+
get_data_root_dir = get_data_root_dir_local
19+
if 'get_output_dir' not in dir():
20+
get_output_dir = get_data_root_dir_local
21+
22+
delete_output = 'SAVE_OUTPUT' not in os.environ
23+
24+
25+
def delete_file(file):
26+
if delete_output:
27+
os.remove(file)
28+
29+
30+
# Example code:
31+
def filter(raster, options, output_path):
32+
raster.filter(raster.bounds, options)
33+
raster.save(output_path)
34+
35+
36+
def get_random_kernel(cols, rows):
37+
custom_kernel = [0.0] * (cols * rows)
38+
for y in range(rows):
39+
for x in range(cols):
40+
custom_kernel[y*cols + x] = random.random()
41+
42+
return custom_kernel
43+
44+
45+
size: int = 5
46+
sigma: float = 1.5
47+
angle: float = 45
48+
custom_kernel = get_random_kernel(size, 7)
49+
custom_complex = ConvolutionFilter.to_complex(custom_kernel)
50+
kernel_filters = [
51+
# convolution filters
52+
ConvolutionFilterOptions(ConvolutionFilter.get_emboss_3x3()),
53+
ConvolutionFilterOptions(ConvolutionFilter.get_emboss_5x5()),
54+
ConvolutionFilterOptions(ConvolutionFilter.get_sharpen_3x3()),
55+
ConvolutionFilterOptions(ConvolutionFilter.get_sharpen_5x5()),
56+
ConvolutionFilterOptions(ConvolutionFilter.get_blur_box(size)),
57+
ConvolutionFilterOptions(ConvolutionFilter.get_blur_motion(size, angle)),
58+
ConvolutionFilterOptions(ConvolutionFilter.get_gaussian(size, sigma)),
59+
ConvolutionFilterOptions(custom_kernel),
60+
GaussianBlurFilterOptions(size, sigma),
61+
SharpenFilterOptions(size, sigma),
62+
MedianFilterOptions(size),
63+
# deconvolution filters
64+
DeconvolutionFilterOptions(ConvolutionFilter.get_gaussian(size, sigma)),
65+
DeconvolutionFilterOptions(custom_kernel),
66+
DeconvolutionFilterOptions(custom_complex),
67+
GaussWienerFilterOptions(size, sigma),
68+
MotionWienerFilterOptions(size, sigma, angle)
69+
]
70+
71+
data_dir = os.path.join(get_data_root_dir(), 'png')
72+
input_paths = [
73+
os.path.join(data_dir, "template.png")
74+
]
75+
outputs = []
76+
for input_path in input_paths:
77+
for i, options in enumerate(kernel_filters):
78+
with Image.load(input_path) as image:
79+
output_path = f"{input_path}-{i}.png"
80+
if aspycore.is_assignable(image, RasterImage):
81+
raster = aspycore.as_of(image, RasterImage)
82+
filter(raster, options, output_path)
83+
outputs.append(output_path)
84+
elif aspycore.is_assignable(image, VectorImage):
85+
vector = aspycore.as_of(image, VectorImage)
86+
vector_as_png = input_path + ".png"
87+
if not os.path.exists(vector_as_png):
88+
vector.save(vector_as_png)
89+
outputs.append(vector_as_png)
90+
91+
with Image.load(vector_as_png) as png:
92+
filter(aspycore.as_of(png, RasterImage), options, output_path)
93+
outputs.append(output_path)
94+
95+
# Removing all output files
96+
for p in outputs:
97+
delete_file(p)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# GROUP: TEST_FILE_FORMATS
2+
from aspose.pycore import as_of
3+
from aspose.imaging.fileformats.dicom import DicomImage
4+
from aspose.imaging import Image
5+
import os
6+
7+
8+
# Initialization
9+
def get_data_root_dir_local():
10+
if 'BASE_DIR' in os.environ:
11+
return os.environ["BASE_DIR"]
12+
return "."
13+
14+
15+
if 'get_data_root_dir' not in dir():
16+
get_data_root_dir = get_data_root_dir_local
17+
18+
if 'get_output_dir' not in dir():
19+
get_output_dir = get_data_root_dir_local
20+
21+
22+
# Example code:
23+
print("Running example ModifyDicomTags")
24+
# The path to the documents directory.
25+
data_dir = os.path.join(get_data_root_dir(), 'dicom')
26+
out_file = os.path.join(get_output_dir(), 'output.dcm')
27+
28+
with as_of(Image.load(dataDir + "file.dcm"), DicomImage) as image:
29+
image.file_info.update_tag_at(33, "Test Patient") # "Patient's Name"
30+
image.file_info.add_tag("Angular View Vector", 234)
31+
image.file_info.remove_tag_at(29) # "Station Name"
32+
image.save(out_file)
33+
34+
if 'SAVE_OUTPUT' not in os.environ:
35+
os.remove(out_file)
36+
37+
print("Finished example ModifyDicomTags")
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# GROUP: MODIFYING_AND_CONVERTING_IMAGES
2+
from aspose.pycore import as_of, is_assignable
3+
from aspose.imaging.fileformats.dicom import DicomImage
4+
from aspose.imaging import Image
5+
from aspose.imaging.exif import IHasExifData
6+
from aspose.imaging.imageoptions import DicomOptions
7+
import os
8+
9+
10+
# Initialization
11+
def get_data_root_dir_local():
12+
if 'BASE_DIR' in os.environ:
13+
return os.environ["BASE_DIR"]
14+
return "."
15+
16+
17+
if 'get_data_root_dir' not in dir():
18+
get_data_root_dir = get_data_root_dir_local
19+
20+
if 'get_output_dir' not in dir():
21+
get_output_dir = get_data_root_dir_local
22+
23+
24+
# Example code:
25+
26+
# The path to the documents directory.
27+
data_dir = os.path.join(get_data_root_dir(), 'dicom')
28+
out_file1 = os.path.join(get_output_dir(), 'output.dcm')
29+
out_file2 = os.path.join(get_output_dir(), 'output_remove.dcm')
30+
out_file3 = os.path.join(get_output_dir(), 'output_modify.dcm')
31+
32+
def exportWithMetadata(inputPath, outputPath, exportOptions):
33+
with Image.load(inputPath) as image:
34+
exportOptions.keep_metadata = True
35+
image.save(outputPath, exportOptions)
36+
37+
def removeMetadata(inputPath, outputPath, exportOptions):
38+
with Image.load(inputPath) as image:
39+
image.remove_metadata()
40+
image.save(outputPath, exportOptions)
41+
42+
def modifyMetada(inputPath, outputPath, exportOptions):
43+
with Image.load(inputPath) as image:
44+
if is_assignable(image, IHasExifData):
45+
hasExif = as_of(image, IHasExifData)
46+
if hasExif.exif_data is not None:
47+
hasExif.exif_data.user_comment = f"Modified at {datetime.now()}"
48+
exportOptions.keep_metadata = True
49+
50+
image.save(outputPath, exportOptions)
51+
52+
exportWithMetadata(os.path.join(data_dir, "file.dcm"), out_file1, DicomOptions())
53+
removeMetadata(os.path.join(data_dir, "file.dcm"), out_file2, DicomOptions())
54+
modifyMetada(os.path.join(data_dir, "file.dcm"), out_file3, DicomOptions())
55+
56+
if 'SAVE_OUTPUT' not in os.environ:
57+
os.remove(out_file1)
58+
os.remove(out_file2)
59+
os.remove(out_file3)

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2001-2023 Aspose Pty Ltd
3+
Copyright (c) 2001-2024 Aspose Pty Ltd
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
# API for Image Processing
55

6-
[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.
6+
[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.
77

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

4646
## Platform Independence
4747

48-
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.
48+
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.
4949

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

0 commit comments

Comments
 (0)