Skip to content
Snippets Groups Projects
Commit e3c83f16 authored by Sharon Yates's avatar Sharon Yates Committed by GitHub
Browse files

Merge pull request #12 from Neural-Systems-at-UIO/OOP

Oop
parents 5a114b5b 864326f3
No related branches found
No related tags found
No related merge requests found
Showing
with 93 additions and 7 deletions
......@@ -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
......
......@@ -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=";",
......
......@@ -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)))
......
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)
{ "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
{ "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
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")
{"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
{"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
File added
test_data/PyTest_NL_atlasmaps_fixed/test_s001_nl.png

7.76 KiB

test_data/PyTest_NL_atlasmaps_fixed/test_s001_nl_rbw.png

9.7 KiB

File added
test_data/PyTest_NL_atlasmaps_fixed/test_s002_nl.png

9.13 KiB

test_data/PyTest_NL_atlasmaps_fixed/test_s002_nl_rbw.png

13.4 KiB

File added
test_data/PyTest_NL_atlasmaps_fixed/test_s003_nl.png

12.1 KiB

test_data/PyTest_NL_atlasmaps_fixed/test_s003_nl_rbw.png

17.1 KiB

File added
test_data/PyTest_NL_atlasmaps_fixed/test_s004_nl.png

13.7 KiB

0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment