From 71fdd30604d5f8e8d99dc88ca42eeabb2be73c8d Mon Sep 17 00:00:00 2001 From: sharoncy <s.c.yates@medisin.uio.no> Date: Sat, 27 May 2023 20:23:40 +0200 Subject: [PATCH] Function to create test data Create white images of specified size with square black objects of specified pixel size and pixel location. --- scripts/create_test_data.py | 49 +++++++++++++++++++++++++ test_data/PyTest/test_s001.png | Bin 0 -> 6768 bytes test_data/PyTest/test_s002.png | Bin 0 -> 6768 bytes test_data/PyTest/test_s003.png | Bin 0 -> 6768 bytes test_data/PyTest/test_s004.png | Bin 0 -> 6768 bytes test_data/PyTest/test_s005.png | Bin 0 -> 6768 bytes test_data/create_test_data.py | 43 ---------------------- test_data/testimage.png | Bin 0 -> 5213 bytes test_data/white_image_with_squares.png | Bin 5281 -> 5297 bytes 9 files changed, 49 insertions(+), 43 deletions(-) create mode 100644 scripts/create_test_data.py create mode 100644 test_data/PyTest/test_s001.png create mode 100644 test_data/PyTest/test_s002.png create mode 100644 test_data/PyTest/test_s003.png create mode 100644 test_data/PyTest/test_s004.png create mode 100644 test_data/PyTest/test_s005.png delete mode 100644 test_data/create_test_data.py create mode 100644 test_data/testimage.png diff --git a/scripts/create_test_data.py b/scripts/create_test_data.py new file mode 100644 index 0000000..1e196fe --- /dev/null +++ b/scripts/create_test_data.py @@ -0,0 +1,49 @@ +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) + + +"""This is used to generate the test data""" + +def generate_image_with_squares(width, height, square_diameter, square_locations, num_images): + # Create a white image with objects of specified size at specified x, y locations + for i in range(1, num_images + 1): + 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 - 1), y + (square_size - 1)) + # square defines the bounding box + draw.rectangle(square, fill=(0, 0, 0)) + + file_name = f"../test_data/PyTest/test_s00{i}.png" + image.save(file_name, "PNG") + +# Example usage +width = 1500 # Specify the width of the image in pixels +height = 1000 # Specify the height of the image in pixels +square_diameter = 10 # Specify the size of the black squares in pixels +square_locations = [(500, 500), (500, 600), (500, 700), (1000, 500), (1000,600),(1000,700)] # Specify the x, y locations of the black squares +num_images = 5 + +# Generate the white image with black squares +image = generate_image_with_squares(width, height, square_diameter, square_locations,num_images) + diff --git a/test_data/PyTest/test_s001.png b/test_data/PyTest/test_s001.png new file mode 100644 index 0000000000000000000000000000000000000000..260f98b911f9071cb51e7d5a47bd263866afae6b GIT binary patch literal 6768 zcmeAS@N?(olHy`uVBq!ia0y~yV7<e@!2E)P2`J*7vw9N)gOs_ai(^Q|oVT|&_8v9h zVLkZx;NR_M?l&qQ<i26Na+0`aL_yhiexUM(^uO1cfi%NDk132milf5_#A6I(1Cj~~ zr$8JQ7fB%5(4YZQC?Jpu5@TA#10)?BMm3EF#Au2b%^IU+#AsnTT5F6}pQBBJ(YDcO zBXP8~4D1{Xz9vEAYB`1jmBz)NckS-iWqcq~Z++nR4hniOXWm_t26cw)jxQbU4UKjS zsntJzu!^0b;NF=#d)~cE_GYj+dY|uuogM|jyLtClP;b8Be4*xO4}NqggIZ%cJ6<s| z%rQ4MU%&hJ4Iu`<kK38|^m~&Zya(Ro?FEfMJt&T$mJ3G*CPoJ)245>=bZm8Wka=|A gd~^n3Fixe^9phF#p7cH7F{oSP>FVdQ&MBb@0Gi}9uK)l5 literal 0 HcmV?d00001 diff --git a/test_data/PyTest/test_s002.png b/test_data/PyTest/test_s002.png new file mode 100644 index 0000000000000000000000000000000000000000..260f98b911f9071cb51e7d5a47bd263866afae6b GIT binary patch literal 6768 zcmeAS@N?(olHy`uVBq!ia0y~yV7<e@!2E)P2`J*7vw9N)gOs_ai(^Q|oVT|&_8v9h zVLkZx;NR_M?l&qQ<i26Na+0`aL_yhiexUM(^uO1cfi%NDk132milf5_#A6I(1Cj~~ zr$8JQ7fB%5(4YZQC?Jpu5@TA#10)?BMm3EF#Au2b%^IU+#AsnTT5F6}pQBBJ(YDcO zBXP8~4D1{Xz9vEAYB`1jmBz)NckS-iWqcq~Z++nR4hniOXWm_t26cw)jxQbU4UKjS zsntJzu!^0b;NF=#d)~cE_GYj+dY|uuogM|jyLtClP;b8Be4*xO4}NqggIZ%cJ6<s| z%rQ4MU%&hJ4Iu`<kK38|^m~&Zya(Ro?FEfMJt&T$mJ3G*CPoJ)245>=bZm8Wka=|A gd~^n3Fixe^9phF#p7cH7F{oSP>FVdQ&MBb@0Gi}9uK)l5 literal 0 HcmV?d00001 diff --git a/test_data/PyTest/test_s003.png b/test_data/PyTest/test_s003.png new file mode 100644 index 0000000000000000000000000000000000000000..260f98b911f9071cb51e7d5a47bd263866afae6b GIT binary patch literal 6768 zcmeAS@N?(olHy`uVBq!ia0y~yV7<e@!2E)P2`J*7vw9N)gOs_ai(^Q|oVT|&_8v9h zVLkZx;NR_M?l&qQ<i26Na+0`aL_yhiexUM(^uO1cfi%NDk132milf5_#A6I(1Cj~~ zr$8JQ7fB%5(4YZQC?Jpu5@TA#10)?BMm3EF#Au2b%^IU+#AsnTT5F6}pQBBJ(YDcO zBXP8~4D1{Xz9vEAYB`1jmBz)NckS-iWqcq~Z++nR4hniOXWm_t26cw)jxQbU4UKjS zsntJzu!^0b;NF=#d)~cE_GYj+dY|uuogM|jyLtClP;b8Be4*xO4}NqggIZ%cJ6<s| z%rQ4MU%&hJ4Iu`<kK38|^m~&Zya(Ro?FEfMJt&T$mJ3G*CPoJ)245>=bZm8Wka=|A gd~^n3Fixe^9phF#p7cH7F{oSP>FVdQ&MBb@0Gi}9uK)l5 literal 0 HcmV?d00001 diff --git a/test_data/PyTest/test_s004.png b/test_data/PyTest/test_s004.png new file mode 100644 index 0000000000000000000000000000000000000000..260f98b911f9071cb51e7d5a47bd263866afae6b GIT binary patch literal 6768 zcmeAS@N?(olHy`uVBq!ia0y~yV7<e@!2E)P2`J*7vw9N)gOs_ai(^Q|oVT|&_8v9h zVLkZx;NR_M?l&qQ<i26Na+0`aL_yhiexUM(^uO1cfi%NDk132milf5_#A6I(1Cj~~ zr$8JQ7fB%5(4YZQC?Jpu5@TA#10)?BMm3EF#Au2b%^IU+#AsnTT5F6}pQBBJ(YDcO zBXP8~4D1{Xz9vEAYB`1jmBz)NckS-iWqcq~Z++nR4hniOXWm_t26cw)jxQbU4UKjS zsntJzu!^0b;NF=#d)~cE_GYj+dY|uuogM|jyLtClP;b8Be4*xO4}NqggIZ%cJ6<s| z%rQ4MU%&hJ4Iu`<kK38|^m~&Zya(Ro?FEfMJt&T$mJ3G*CPoJ)245>=bZm8Wka=|A gd~^n3Fixe^9phF#p7cH7F{oSP>FVdQ&MBb@0Gi}9uK)l5 literal 0 HcmV?d00001 diff --git a/test_data/PyTest/test_s005.png b/test_data/PyTest/test_s005.png new file mode 100644 index 0000000000000000000000000000000000000000..260f98b911f9071cb51e7d5a47bd263866afae6b GIT binary patch literal 6768 zcmeAS@N?(olHy`uVBq!ia0y~yV7<e@!2E)P2`J*7vw9N)gOs_ai(^Q|oVT|&_8v9h zVLkZx;NR_M?l&qQ<i26Na+0`aL_yhiexUM(^uO1cfi%NDk132milf5_#A6I(1Cj~~ zr$8JQ7fB%5(4YZQC?Jpu5@TA#10)?BMm3EF#Au2b%^IU+#AsnTT5F6}pQBBJ(YDcO zBXP8~4D1{Xz9vEAYB`1jmBz)NckS-iWqcq~Z++nR4hniOXWm_t26cw)jxQbU4UKjS zsntJzu!^0b;NF=#d)~cE_GYj+dY|uuogM|jyLtClP;b8Be4*xO4}NqggIZ%cJ6<s| z%rQ4MU%&hJ4Iu`<kK38|^m~&Zya(Ro?FEfMJt&T$mJ3G*CPoJ)245>=bZm8Wka=|A gd~^n3Fixe^9phF#p7cH7F{oSP>FVdQ&MBb@0Gi}9uK)l5 literal 0 HcmV?d00001 diff --git a/test_data/create_test_data.py b/test_data/create_test_data.py deleted file mode 100644 index f5f70f5..0000000 --- a/test_data/create_test_data.py +++ /dev/null @@ -1,43 +0,0 @@ -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 diff --git a/test_data/testimage.png b/test_data/testimage.png new file mode 100644 index 0000000000000000000000000000000000000000..77cdf70f52d8d4532d1a1563659b3e54959ebe14 GIT binary patch literal 5213 zcmeAS@N?(olHy`uVBq!ia0y~yV15C@985rwLkFEVGcbs#c)B=-RLpsM?I7;~1%U$_ zF8wXHb9=x!@eSvvGqYy$GcZ)#uD1p%w=jOkz#x!thmk?yzz${xhlWCSh6aYmd<+bX z$7C58n0kPUSR~3B7&r_@6^;haXrdU+3Zo^(X!$r=D~wi}qfLd;2GVG=aJ1Dt+E*Cu uA&qt*N4w3Vg9W2QB%>opLulO0tRaEx?B<7?uL8#b89ZJ6T-G@yGywpmt$>FB literal 0 HcmV?d00001 diff --git a/test_data/white_image_with_squares.png b/test_data/white_image_with_squares.png index f2caf78a8adb2896d8a8a125dadd167c65de4add..ff9fbdb168a9ec47ad27b731e1e5ec00bd116606 100644 GIT binary patch delta 276 zcmZ3exlwb1ieZJPi(^Q|oVPa|vt$?rSRA+C{9nJb)|{JpQla+J4)H67D{tP7XJ9yR z{oC&<1_p)?KAQvCzcC5LU1$EWX6DX$AMU-2^JifAVP`YhknulPLfQ8!W}vDAk0&2w z{36_N{VT(d`m|?NhpKm1+cGlzc!jQP^Fy{S=E)9B*+LIWZ5bNs^V8O;@7cclx-i2k zoJxg3N*NwJhMC*={us!*|D0*%>&<~~<hR*u$oQ2JqO4(lHq6L>&k83yGX9?&!}3q; a5935djl()E@BaZcFnGH9xvX<aXaWE?BYL<1 delta 228 zcmdm}xlnV0ia~~_i(^Q|oVPbFX2viIusE*W@h3P=z2Jj`S=`q^(StQ+#=C#BGBEtf zyMLXTfuSLNvmv7t)8r5AcZ5Iek~?sJ*38$O@87=r%EHia{$b(dK*s-*=L-K5-m{MV zz<*=o>%#YL-+j%=a3KFVTyEomZl=i>n979Kzh-3kQ*B&q`*82wz4I6Xo?=(RU~djH zr$(xO@<;anoHOq3y~n`7VDn*fB0CrJWCx}<Vn3J{yC@xXPIoQ<N-%i3`njxgN@xNA Dn<{6N -- GitLab