Skip to content
Snippets Groups Projects
Commit 4897218d authored by Sharon Yates's avatar Sharon Yates
Browse files

Changed the scaling method for flat to segmentation

The reports now give same region pixels as Nutil
parent 01b6f3d6
No related branches found
No related tags found
No related merge requests found
Showing
with 31 additions and 11 deletions
......@@ -67,7 +67,6 @@ def transform_to_registration(seg_height, seg_width, reg_height, reg_width):
x_scale = reg_width / seg_width
return y_scale, x_scale
# related to coordinate extraction
def find_matching_pixels(segmentation, id):
"""This function returns the Y and X coordinates of all the pixels in the segmentation that match the id provided."""
......@@ -261,8 +260,8 @@ def segmentation_to_atlas_space(
else:
segmentation = cv2.imread(segmentation_path)
# if pixel_id == "auto":
if True:
if pixel_id == "auto":
# Remove the background from the segmentation
segmentation_no_background = segmentation[~np.all(segmentation == 0, axis=2)]
# pixel_id = np.vstack(
......@@ -294,6 +293,7 @@ def segmentation_to_atlas_space(
y_scale, x_scale = transform_to_registration(
seg_height, seg_width, reg_height, reg_width
)
centroids, points = None, None
if method in ["per_object", "all"]:
......
......@@ -166,7 +166,6 @@ def rescale_image(image, rescaleXY):
w, h = rescaleXY
return cv2.resize(image, (h, w), interpolation=cv2.INTER_NEAREST)
def assign_labels_to_image(image, labelfile):
w, h = image.shape
allen_id_image = np.zeros((h, w)) # create an empty image array
......@@ -179,8 +178,10 @@ def assign_labels_to_image(image, labelfile):
return allen_id_image
def count_pixels_per_label(image):
def count_pixels_per_label(image, scale_factor=False):
unique_ids, counts = np.unique(image, return_counts=True)
if scale_factor:
counts = counts * scale_factor
area_per_label = list(zip(unique_ids, counts))
df_area_per_label = pd.DataFrame(area_per_label, columns=["idx", "region_area"])
return df_area_per_label
......@@ -200,10 +201,15 @@ def flat_to_dataframe(
print("image shape open", image.shape)
if rescaleXY:
image = rescale_image(image, rescaleXY)
image_shapeY, image_shapeX = image.shape[0], image.shape[1]
image_pixels = image_shapeY * image_shapeX
seg_pixels = rescaleXY[0] * rescaleXY[1]
scale_factor = seg_pixels / image_pixels
else:
scale_factor = False
if (image_vector is None) or (volume is None):
allen_id_image = assign_labels_to_image(image, labelfile)
else:
allen_id_image = image
df_area_per_label = count_pixels_per_label(allen_id_image)
df_area_per_label = count_pixels_per_label(allen_id_image, scale_factor)
return df_area_per_label
{ "volume_path": "allen2017",
"label_path": "PyNutil/annotation_volumes/allen2017_colours.csv",
"segmentation_folder": "PyNutil/test_data/PyTest_seg",
"alignment_json": "PyNutil/test_data/PyNutil_testdataset_Nonlin_SY_fixed.json",
"alignment_json": "PyNutil/test_data/PyNutil_testdataset_Nonlin_SY_fixed_bigcaudoputamen.json",
"nonlinear": true,
"colour": [0, 0, 0],
"points_json_path": "PyNutil/outputs/test8_PyNutil.json"
"points_json_path": "PyNutil/outputs/test8_PyNutil_use_flat.json"
}
\ No newline at end of file
......@@ -3,11 +3,13 @@ from PyNutil import PyNutil
pnt = PyNutil(settings_file=r"PyNutil/test/test8_PyNutil_fixed.json")
##Use flat can be set to True if you want to use the flat file
# instead of the visualign json (this is only useful for testing and will be removed)
pnt.get_coordinates(object_cutoff=0, use_flat=False)
pnt.get_coordinates(object_cutoff=0, use_flat=True)
pnt.quantify_coordinates()
pnt.save_analysis("PyNutil/outputs/test8_PyNutil")
pnt.save_analysis("PyNutil/outputs/test8_PyNutil_bigcaudoputamen_newatlasmaps")
# remove name, r, g, b, from pixel_
# add to region_areas df
{"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],"markers":[[675.1336898395723, 571.1229946524063, 675.1336898395722, 571.1229946524064], [862.2994652406418, 587.1657754010693, 862.2994652406417, 587.1657754010695], [462.29946524064167, 485.5614973262032, 232.3529411764706, 320.8556149732621], [462.2618138532621, 686.9522625381479, 205.6149732620321, 932.6203208556149], [1065.5080213903743, 479.1443850267384, 1305.0802139037437, 259.89304812834223], [874.0684663788843, 528.257146231987, 832.3529411764705, 360.4278074866309], [1076.6584104086885, 691.7768773152915, 1329.6791443850263, 922.9946524064171]]},
{"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
snr name segmented changed stable%
1 test_s001.png 108266 95135 12%
2 test_s002.png 83702 34124 59%
3 test_s003.png 93593 67152 28%
4 test_s004.png 97022 44431 54%
5 test_s005.png 92810 90411 2%
No preview for this file type
test_data/PyTest_seg/flat_files/test_s001_nl.png

7.76 KiB | W: | H:

test_data/PyTest_seg/flat_files/test_s001_nl.png

9.34 KiB | W: | H:

test_data/PyTest_seg/flat_files/test_s001_nl.png
test_data/PyTest_seg/flat_files/test_s001_nl.png
test_data/PyTest_seg/flat_files/test_s001_nl.png
test_data/PyTest_seg/flat_files/test_s001_nl.png
  • 2-up
  • Swipe
  • Onion skin
test_data/PyTest_seg/flat_files/test_s001_nl_rbw.png

9.7 KiB | W: | H:

test_data/PyTest_seg/flat_files/test_s001_nl_rbw.png

10.5 KiB | W: | H:

test_data/PyTest_seg/flat_files/test_s001_nl_rbw.png
test_data/PyTest_seg/flat_files/test_s001_nl_rbw.png
test_data/PyTest_seg/flat_files/test_s001_nl_rbw.png
test_data/PyTest_seg/flat_files/test_s001_nl_rbw.png
  • 2-up
  • Swipe
  • Onion skin
test_data/PyTest_seg/flat_files/test_s002_nl_rbw.png

13.4 KiB | W: | H:

test_data/PyTest_seg/flat_files/test_s002_nl_rbw.png

13.4 KiB | W: | H:

test_data/PyTest_seg/flat_files/test_s002_nl_rbw.png
test_data/PyTest_seg/flat_files/test_s002_nl_rbw.png
test_data/PyTest_seg/flat_files/test_s002_nl_rbw.png
test_data/PyTest_seg/flat_files/test_s002_nl_rbw.png
  • 2-up
  • Swipe
  • Onion skin
test_data/PyTest_seg/flat_files/test_s003_nl_rbw.png

17.1 KiB | W: | H:

test_data/PyTest_seg/flat_files/test_s003_nl_rbw.png

17.2 KiB | W: | H:

test_data/PyTest_seg/flat_files/test_s003_nl_rbw.png
test_data/PyTest_seg/flat_files/test_s003_nl_rbw.png
test_data/PyTest_seg/flat_files/test_s003_nl_rbw.png
test_data/PyTest_seg/flat_files/test_s003_nl_rbw.png
  • 2-up
  • Swipe
  • Onion skin
test_data/PyTest_seg/flat_files/test_s004_nl_rbw.png

18.2 KiB | W: | H:

test_data/PyTest_seg/flat_files/test_s004_nl_rbw.png

18.3 KiB | W: | H:

test_data/PyTest_seg/flat_files/test_s004_nl_rbw.png
test_data/PyTest_seg/flat_files/test_s004_nl_rbw.png
test_data/PyTest_seg/flat_files/test_s004_nl_rbw.png
test_data/PyTest_seg/flat_files/test_s004_nl_rbw.png
  • 2-up
  • Swipe
  • Onion skin
test_data/PyTest_seg/flat_files/test_s005_nl_rbw.png

15.2 KiB | W: | H:

test_data/PyTest_seg/flat_files/test_s005_nl_rbw.png

15.1 KiB | W: | H:

test_data/PyTest_seg/flat_files/test_s005_nl_rbw.png
test_data/PyTest_seg/flat_files/test_s005_nl_rbw.png
test_data/PyTest_seg/flat_files/test_s005_nl_rbw.png
test_data/PyTest_seg/flat_files/test_s005_nl_rbw.png
  • 2-up
  • Swipe
  • Onion skin
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