diff --git a/PyNutil/counting_and_load.py b/PyNutil/counting_and_load.py index 2c7b46eebe62b1716a674b0d7ea4022a906d56b7..f5b1f8dba50e81fab7d13622bf2db89a5de5fd06 100644 --- a/PyNutil/counting_and_load.py +++ b/PyNutil/counting_and_load.py @@ -101,6 +101,13 @@ def pixel_count_per_region( new_rows.append(row) df_counts_per_label_name = pd.DataFrame(new_rows) + + #Task for Sharon: + #If you can get the areas per region from the flat file here + #you can then use those areas to calculate the load per region here + # and add to dataframe + #see messing around pyflat.py + return df_counts_per_label_name diff --git a/PyNutil/main.py b/PyNutil/main.py index b4944882c1ecfe729f0b6680395aa5e3f3a0825e..8e045e6bb055a76d14e7aa9f17dd4cf7ea28b45d 100644 --- a/PyNutil/main.py +++ b/PyNutil/main.py @@ -211,12 +211,13 @@ class PyNutil: labeled_points, labeled_points_centroids, self.atlas_labels ) prev_pl = 0 + prev_cl = 0 per_section_df = [] current_centroids = None current_points = None - for pl in self.points_len: + for pl,cl in zip(self.points_len, self.centroids_len): if hasattr(self, "centroids"): - current_centroids = labeled_points_centroids[prev_pl : prev_pl + pl] + current_centroids = labeled_points_centroids[prev_cl : prev_cl + cl] if hasattr(self, "pixel_points"): current_points = labeled_points[prev_pl : prev_pl + pl] current_df = pixel_count_per_region( @@ -224,6 +225,7 @@ class PyNutil: ) per_section_df.append(current_df) prev_pl += pl + prev_cl += cl self.labeled_points = labeled_points self.labeled_points_centroids = labeled_points_centroids @@ -272,7 +274,7 @@ class PyNutil: self.segmentation_filenames, self.per_section_df, ): - split_fn = fn.split("/")[-1].split(".")[0] + split_fn = fn.split(os.sep)[-1].split(".")[0] df.to_csv( f"{output_folder}/per_section_reports/{split_fn}.csv", sep=";", diff --git a/messing_around_files/testing_openflatfile.py b/messing_around_files/testing_openflatfile.py index bc02f9546d82010dc0d86bf0aa22928939ec8a73..183e403e213e8a6754851414b08f634325c79d2b 100644 --- a/messing_around_files/testing_openflatfile.py +++ b/messing_around_files/testing_openflatfile.py @@ -39,7 +39,7 @@ with open(base, "rb") as f: """assign label file values into image array""" labelfile = pd.read_csv(r"metadata/annotation_volumes\allen2017_colours.csv") -labelfile[] +#labelfile[] print(list(zip(val,count))) diff --git a/scripts/create_test_data.py b/scripts/create_test_data.py new file mode 100644 index 0000000000000000000000000000000000000000..1e196fe6e11282256ae0766f0bf09a17e7dd66d0 --- /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/test7_PyNutil.json b/test/test7_PyNutil.json new file mode 100644 index 0000000000000000000000000000000000000000..07d54af0c9e47c394b736c5e9b82c205927535de --- /dev/null +++ b/test/test7_PyNutil.json @@ -0,0 +1,8 @@ +{ "volume_path": "allen2017", + "label_path": "annotation_volumes/allen2017_colours.csv", + "segmentation_folder": "test_data/PyTest_seg", + "alignment_json": "test_data/PyNutil_testdataset_Nonlin_SY.json", + "nonlinear": true, + "colour": [0, 0, 0], + "points_json_path": "outputs/test7_PyNutil.json" +} \ No newline at end of file diff --git a/test/test8_PyNutil_fixed.json b/test/test8_PyNutil_fixed.json new file mode 100644 index 0000000000000000000000000000000000000000..842b226f80dec6358d62fbd09e8a5b2ca11e08aa --- /dev/null +++ b/test/test8_PyNutil_fixed.json @@ -0,0 +1,8 @@ +{ "volume_path": "allen2017", + "label_path": "annotation_volumes/allen2017_colours.csv", + "segmentation_folder": "test_data/PyTest_seg", + "alignment_json": "test_data/PyNutil_testdataset_Nonlin_SY_fixed.json", + "nonlinear": true, + "colour": [0, 0, 0], + "points_json_path": "outputs/test8_PyNutil.json" +} \ No newline at end of file diff --git a/testOOP.py b/testOOP.py index ce0c65d1cab9a28d37c5531d511f8b82f454ffad..e4256a0a1af024534bcc152da2f901bb24b1de5e 100644 --- a/testOOP.py +++ b/testOOP.py @@ -1,11 +1,11 @@ from PyNutil import PyNutil -pnt = PyNutil(settings_file=r"test/PVMouse_81264_test.json") -# pnt = PyNutil(settings_file=r"test/test3.json") +pnt = PyNutil(settings_file=r"test/test8_PyNutil_fixed.json") +# pnt = PyNutil(settings_file=r"test/test7_PyNutil.json") # pnt.build_quantifier() pnt.get_coordinates(object_cutoff=0) pnt.quantify_coordinates() -pnt.save_analysis("outputs/test4_2017") +pnt.save_analysis("outputs/test8_PyNutil") diff --git a/test_data/PyNutil_testdataset_Nonlin_SY.json b/test_data/PyNutil_testdataset_Nonlin_SY.json new file mode 100644 index 0000000000000000000000000000000000000000..2a572342f3f829aec0e4661800cc1b2885662e35 --- /dev/null +++ b/test_data/PyNutil_testdataset_Nonlin_SY.json @@ -0,0 +1,6 @@ +{"name":"PyNutil_testdataset","target":"ABA_Mouse_CCFv3_2017_25um.cutlas","target-resolution":[456.0, 528.0, 320.0],"slices":[ +{"filename":"test_s001.png","nr":1,"width":1500,"height":1000,"anchoring":[-5.145275115966797, 361.8014440433213, 331.1490739071843, 456.0, 0.0, 0.0, 0.0, 0.0, -320.0]}, +{"filename":"test_s002.png","nr":2,"width":1500,"height":1000,"anchoring":[-3.8589563369750977, 318.7157039711191, 340.24552914037605, 456.0, 0.0, 0.0, 0.0, 0.0, -320.0],"markers":[[636.8098159509204, 603.4958601655935, 672.6993865030674, 593.3762649494021], [902.9868982011025, 615.5567336628567, 843.8650306748466, 610.8555657773691], [561.2609204260139, 750.3661510917975, 558.5889570552147, 775.5289788408462]]}, +{"filename":"test_s003.png","nr":3,"width":1500,"height":1000,"anchoring":[-2.8942172527313232, 275.6299638989171, 350.0189942541106, 456.0, 0.0, 0.0, 0.0, 0.0, -320.0],"markers":[[761.0429447852762, 629.2548298068077, 761.0429447852761, 629.2548298068077], [204.29447852760745, 613.6154553817848, 365.3374233128834, 612.695492180313], [482.6376861494953, 714.9876920193675, 623.0061349693251, 747.0101195952162], [434.00208292806684, 606.7676930120547, 578.8343558282207, 601.6559337626494], [959.8159509202455, 636.6145354185834, 980.0613496932516, 628.3348666053357], [957.8161415293836, 523.3987679117937, 953.3742331288344, 547.3781048758049]]}, +{"filename":"test_s004.png","nr":4,"width":1500,"height":1000,"anchoring":[-3.0282087922096252, 232.54422382671487, 364.1366059225139, 456.0, 0.0, 0.0, 0.0, 0.0, -320.0],"markers":[[522.6993865030674, 712.9714811407543, 519.9386503067485, 715.7313707451704], [630.6438500513034, 523.1833943062713, 550.3067484662577, 519.7792088316469], [916.4047791164191, 534.1886045162021, 962.5766871165645, 523.4590616375344], [950.8076359295408, 705.46368100121, 949.6932515337423, 701.0119595216191], [1096.1208774051677, 649.3153717520049, 1099.6932515337426, 656.8537258509658], [1030.2378410339393, 594.2011916220456, 1065.644171779141, 604.4158233670653]]}, +{"filename":"test_s005.png","nr":5,"width":1500,"height":1000,"anchoring":[-0.6163610816001892, 189.45848375451277, 374.2485759765199, 456.0, 0.0, 0.0, 0.0, 0.0, -320.0],"markers":[[6.441717791411037, 588.7764489420423, 186.80981595092024, 425.0229990800368], [766.3836793259812, 987.3315412211099, 834.6625766871166, 946.6421343146276], [447.4522362685242, 740.6361518118404, 565.9509202453987, 643.0542778288868], [392.2943778764543, 594.4761834437141, 542.9447852760735, 478.3808647654094], [1117.436664514756, 564.5422630203066, 788.6503067484659, 422.2631094756209], [1045.7025247722827, 975.3508578153971, 893.5582822085888, 873.045078196872]]}]} \ No newline at end of file diff --git a/test_data/PyNutil_testdataset_Nonlin_SY_fixed.json b/test_data/PyNutil_testdataset_Nonlin_SY_fixed.json new file mode 100644 index 0000000000000000000000000000000000000000..54453c095748d1dc5c77ff42a69c39cb0a61ca8c --- /dev/null +++ b/test_data/PyNutil_testdataset_Nonlin_SY_fixed.json @@ -0,0 +1,6 @@ +{"name":"PyNutil_testdataset","target":"ABA_Mouse_CCFv3_2017_25um.cutlas","target-resolution":[456.0, 528.0, 320.0],"slices":[ +{"filename":"test_s001.png","nr":1,"width":1500,"height":1000,"anchoring":[-5.145275115966797, 361.8014440433213, 331.1490739071843, 456.0, 0.0, 0.0, 0.0, 0.0, -320.0]}, +{"filename":"test_s002.png","nr":2,"width":1500,"height":1000,"anchoring":[-3.8589563369750977, 318.7157039711191, 340.24552914037605, 456.0, 0.0, 0.0, 0.0, 0.0, -320.0],"markers":[[636.8098159509204, 603.4958601655935, 672.6993865030674, 593.3762649494021], [902.9868982011025, 615.5567336628567, 843.8650306748466, 610.8555657773691], [561.2609204260139, 750.3661510917975, 558.5889570552147, 775.5289788408462]]}, +{"filename":"test_s003.png","nr":3,"width":1500,"height":1000,"anchoring":[-2.8942172527313232, 275.6299638989171, 350.0189942541106, 456.0, 0.0, 0.0, 0.0, 0.0, -320.0],"markers":[[761.0429447852762, 629.2548298068077, 761.0429447852761, 629.2548298068077], [204.29447852760745, 613.6154553817848, 365.3374233128834, 612.695492180313], [482.6376861494953, 714.9876920193675, 623.0061349693251, 747.0101195952162], [434.00208292806684, 606.7676930120547, 578.8343558282207, 601.6559337626494], [959.8159509202455, 636.6145354185834, 980.0613496932516, 628.3348666053357], [957.8161415293836, 523.3987679117937, 953.3742331288344, 547.3781048758049]]}, +{"filename":"test_s004.png","nr":4,"width":1500,"height":1000,"anchoring":[-3.0282087922096252, 232.54422382671487, 364.1366059225139, 456.0, 0.0, 0.0, 0.0, 0.0, -320.0],"markers":[[522.6993865030674, 712.9714811407543, 530.6338374725239, 715.7313707451705], [630.6438500513034, 523.1833943062713, 550.3067484662577, 519.7792088316469], [916.4047791164191, 534.1886045162021, 962.5766871165645, 523.4590616375344], [950.8076359295408, 705.46368100121, 949.6932515337423, 701.0119595216191], [1096.1208774051677, 649.3153717520049, 1099.6932515337426, 656.8537258509658], [1030.2378410339393, 594.2011916220456, 1065.644171779141, 604.4158233670653]]}, +{"filename":"test_s005.png","nr":5,"width":1500,"height":1000,"anchoring":[-0.6163610816001892, 189.45848375451277, 374.2485759765199, 456.0, 0.0, 0.0, 0.0, 0.0, -320.0],"markers":[[6.441717791411037, 588.7764489420423, 186.80981595092024, 425.0229990800368], [766.3836793259812, 987.3315412211099, 834.6625766871166, 946.6421343146276], [447.4522362685242, 740.6361518118404, 565.9509202453987, 643.0542778288868], [392.2943778764543, 594.4761834437141, 542.9447852760735, 478.3808647654094], [1117.436664514756, 564.5422630203066, 788.6503067484659, 422.2631094756209], [1045.7025247722827, 975.3508578153971, 893.5582822085888, 873.045078196872]]}]} \ No newline at end of file diff --git a/test_data/PyTest_NL_atlasmaps_fixed/test_s001_nl.flat b/test_data/PyTest_NL_atlasmaps_fixed/test_s001_nl.flat new file mode 100644 index 0000000000000000000000000000000000000000..e82b1e4b1019ffa83475844787dc639b2bbaa83f Binary files /dev/null and b/test_data/PyTest_NL_atlasmaps_fixed/test_s001_nl.flat differ diff --git a/test_data/PyTest_NL_atlasmaps_fixed/test_s001_nl.png b/test_data/PyTest_NL_atlasmaps_fixed/test_s001_nl.png new file mode 100644 index 0000000000000000000000000000000000000000..b29e104e0c9760e86cddf9236e4ad4f0746d21dd Binary files /dev/null and b/test_data/PyTest_NL_atlasmaps_fixed/test_s001_nl.png differ diff --git a/test_data/PyTest_NL_atlasmaps_fixed/test_s001_nl_rbw.png b/test_data/PyTest_NL_atlasmaps_fixed/test_s001_nl_rbw.png new file mode 100644 index 0000000000000000000000000000000000000000..742cf759f7cfe7cda135d46ce0bbd6f8669c3369 Binary files /dev/null and b/test_data/PyTest_NL_atlasmaps_fixed/test_s001_nl_rbw.png differ diff --git a/test_data/PyTest_NL_atlasmaps_fixed/test_s002_nl.flat b/test_data/PyTest_NL_atlasmaps_fixed/test_s002_nl.flat new file mode 100644 index 0000000000000000000000000000000000000000..d4355f6e835a0b278c9e7e69b736e4214b7987e9 Binary files /dev/null and b/test_data/PyTest_NL_atlasmaps_fixed/test_s002_nl.flat differ diff --git a/test_data/PyTest_NL_atlasmaps_fixed/test_s002_nl.png b/test_data/PyTest_NL_atlasmaps_fixed/test_s002_nl.png new file mode 100644 index 0000000000000000000000000000000000000000..fe36b91a874fd8f4ac9e9b704b9de3a5e0e9ce6d Binary files /dev/null and b/test_data/PyTest_NL_atlasmaps_fixed/test_s002_nl.png differ diff --git a/test_data/PyTest_NL_atlasmaps_fixed/test_s002_nl_rbw.png b/test_data/PyTest_NL_atlasmaps_fixed/test_s002_nl_rbw.png new file mode 100644 index 0000000000000000000000000000000000000000..5455ca268be872bc4ab9233344a3e5dd0c95b0b9 Binary files /dev/null and b/test_data/PyTest_NL_atlasmaps_fixed/test_s002_nl_rbw.png differ diff --git a/test_data/PyTest_NL_atlasmaps_fixed/test_s003_nl.flat b/test_data/PyTest_NL_atlasmaps_fixed/test_s003_nl.flat new file mode 100644 index 0000000000000000000000000000000000000000..e8f61cf8bbefbbaffe390a0ae8b8d004f7f53c89 Binary files /dev/null and b/test_data/PyTest_NL_atlasmaps_fixed/test_s003_nl.flat differ diff --git a/test_data/PyTest_NL_atlasmaps_fixed/test_s003_nl.png b/test_data/PyTest_NL_atlasmaps_fixed/test_s003_nl.png new file mode 100644 index 0000000000000000000000000000000000000000..632377cabe0d35595e116cf0c075d6aacbb393c7 Binary files /dev/null and b/test_data/PyTest_NL_atlasmaps_fixed/test_s003_nl.png differ diff --git a/test_data/PyTest_NL_atlasmaps_fixed/test_s003_nl_rbw.png b/test_data/PyTest_NL_atlasmaps_fixed/test_s003_nl_rbw.png new file mode 100644 index 0000000000000000000000000000000000000000..26e69527bf65ca3f064ef6989ae08848ed17a104 Binary files /dev/null and b/test_data/PyTest_NL_atlasmaps_fixed/test_s003_nl_rbw.png differ diff --git a/test_data/PyTest_NL_atlasmaps_fixed/test_s004_nl.flat b/test_data/PyTest_NL_atlasmaps_fixed/test_s004_nl.flat new file mode 100644 index 0000000000000000000000000000000000000000..cc166d7bd1befd03c89b8fa9e857d56b979f9aba Binary files /dev/null and b/test_data/PyTest_NL_atlasmaps_fixed/test_s004_nl.flat differ diff --git a/test_data/PyTest_NL_atlasmaps_fixed/test_s004_nl.png b/test_data/PyTest_NL_atlasmaps_fixed/test_s004_nl.png new file mode 100644 index 0000000000000000000000000000000000000000..1518143b4d86be116472f1d90e7148705f3ea3d9 Binary files /dev/null and b/test_data/PyTest_NL_atlasmaps_fixed/test_s004_nl.png differ diff --git a/test_data/PyTest_NL_atlasmaps_fixed/test_s004_nl_rbw.png b/test_data/PyTest_NL_atlasmaps_fixed/test_s004_nl_rbw.png new file mode 100644 index 0000000000000000000000000000000000000000..23472c94287db4506c2892763e51584e2bd06db7 Binary files /dev/null and b/test_data/PyTest_NL_atlasmaps_fixed/test_s004_nl_rbw.png differ diff --git a/test_data/PyTest_NL_atlasmaps_fixed/test_s005_nl.flat b/test_data/PyTest_NL_atlasmaps_fixed/test_s005_nl.flat new file mode 100644 index 0000000000000000000000000000000000000000..3959fdfc31b0823a77ed9a19f5422e439645e0e5 Binary files /dev/null and b/test_data/PyTest_NL_atlasmaps_fixed/test_s005_nl.flat differ diff --git a/test_data/PyTest_NL_atlasmaps_fixed/test_s005_nl.png b/test_data/PyTest_NL_atlasmaps_fixed/test_s005_nl.png new file mode 100644 index 0000000000000000000000000000000000000000..150169f860a5ba7d17a4121fd6a8cb6c99bab27e Binary files /dev/null and b/test_data/PyTest_NL_atlasmaps_fixed/test_s005_nl.png differ diff --git a/test_data/PyTest_NL_atlasmaps_fixed/test_s005_nl_rbw.png b/test_data/PyTest_NL_atlasmaps_fixed/test_s005_nl_rbw.png new file mode 100644 index 0000000000000000000000000000000000000000..a2755bccccb8859a79166a0060527e28964695e2 Binary files /dev/null and b/test_data/PyTest_NL_atlasmaps_fixed/test_s005_nl_rbw.png differ diff --git a/test_data/PyTest_seg/test_s001.png b/test_data/PyTest_seg/test_s001.png new file mode 100644 index 0000000000000000000000000000000000000000..260f98b911f9071cb51e7d5a47bd263866afae6b Binary files /dev/null and b/test_data/PyTest_seg/test_s001.png differ diff --git a/test_data/PyTest_seg/test_s002.png b/test_data/PyTest_seg/test_s002.png new file mode 100644 index 0000000000000000000000000000000000000000..260f98b911f9071cb51e7d5a47bd263866afae6b Binary files /dev/null and b/test_data/PyTest_seg/test_s002.png differ diff --git a/test_data/PyTest_seg/test_s003.png b/test_data/PyTest_seg/test_s003.png new file mode 100644 index 0000000000000000000000000000000000000000..260f98b911f9071cb51e7d5a47bd263866afae6b Binary files /dev/null and b/test_data/PyTest_seg/test_s003.png differ diff --git a/test_data/PyTest_seg/test_s004.png b/test_data/PyTest_seg/test_s004.png new file mode 100644 index 0000000000000000000000000000000000000000..260f98b911f9071cb51e7d5a47bd263866afae6b Binary files /dev/null and b/test_data/PyTest_seg/test_s004.png differ diff --git a/test_data/PyTest_seg/test_s005.png b/test_data/PyTest_seg/test_s005.png new file mode 100644 index 0000000000000000000000000000000000000000..260f98b911f9071cb51e7d5a47bd263866afae6b Binary files /dev/null and b/test_data/PyTest_seg/test_s005.png differ diff --git a/test_data/create_test_data.py b/test_data/create_test_data.py deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/test_data/testimage.png b/test_data/testimage.png new file mode 100644 index 0000000000000000000000000000000000000000..77cdf70f52d8d4532d1a1563659b3e54959ebe14 Binary files /dev/null and b/test_data/testimage.png differ diff --git a/test_data/white_image_with_squares.png b/test_data/white_image_with_squares.png new file mode 100644 index 0000000000000000000000000000000000000000..ff9fbdb168a9ec47ad27b731e1e5ec00bd116606 Binary files /dev/null and b/test_data/white_image_with_squares.png differ