Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PyNutil
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Harry Carey
PyNutil
Commits
27accd35
Commit
27accd35
authored
1 year ago
by
Sharon Yates
Browse files
Options
Downloads
Patches
Plain Diff
Function for creating artificial test images
parent
a55ea7a9
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
test_data/create_test_data.py
+43
-0
43 additions, 0 deletions
test_data/create_test_data.py
test_data/white_image_with_squares.png
+0
-0
0 additions, 0 deletions
test_data/white_image_with_squares.png
with
43 additions
and
0 deletions
test_data/create_test_data.py
+
43
−
0
View file @
27accd35
from
PIL
import
Image
,
ImageDraw
def
generate_test_image
(
width
,
height
,
file_path
):
# Create an empty white image
image
=
Image
.
new
(
mode
=
"
RGB
"
,
size
=
(
width
,
height
),
color
=
(
255
,
255
,
255
))
# Save the image as a PNG file
image
.
save
(
file_path
)
# Example usage
width
=
1000
# Specify the width of the image in pixels
height
=
1000
# Specify the height of the image in pixels
file_path
=
'
testimage.png
'
# Specify the file path for saving the image
# Generate and save the black and white image
generate_test_image
(
width
,
height
,
file_path
)
def
generate_white_image_with_squares
(
width
,
height
,
square_size
,
square_locations
):
# Create a white image with objects of specified size and x, y location
image
=
Image
.
new
(
'
RGB
'
,
(
width
,
height
),
color
=
(
255
,
255
,
255
))
# Create a draw object
draw
=
ImageDraw
.
Draw
(
image
)
# Draw black squares
for
location
in
square_locations
:
x
,
y
=
location
square
=
(
x
,
y
,
x
+
square_size
,
y
+
square_size
)
draw
.
rectangle
(
square
,
fill
=
(
0
,
0
,
0
))
return
image
# Example usage
width
=
1000
# Specify the width of the image in pixels
height
=
1000
# Specify the height of the image in pixels
square_size
=
50
# Specify the size of the black squares in pixels
square_locations
=
[(
500
,
500
),
(
150
,
150
),
(
250
,
250
),
(
750
,
750
)]
# Specify the x, y locations of the black squares
# Generate the white image with black squares
image
=
generate_white_image_with_squares
(
width
,
height
,
square_size
,
square_locations
)
# Save the image
image
.
save
(
'
white_image_with_squares.png
'
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
test_data/white_image_with_squares.png
0 → 100644
+
0
−
0
View file @
27accd35
5.16 KiB
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment