indexError when creating masks
Hi,
I have been trying using the notebook to segment some thin section scans, but I could not make it work. It seems to break at the point of creating the masks using SAM. I can see an image output with some grains recognised, but this is the error message below. Possibly something I missed and not a bug? Thanks! Marco
creating masks using SAM... 100%|██████████| 1516/1516 [02:31<00:00, 9.98it/s] finding overlapping polygons... 1451it [00:01, 726.57it/s] finding best polygons... 100%|██████████| 555/555 [00:09<00:00, 56.12it/s] creating labeled image... 100%|██████████| 530/530 [00:01<00:00, 360.15it/s]
IndexError Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_9148\1514985980.py in
~\Dropbox\University\Frosinone\Sezioni_Sottili\segmentverygrain\segmenteverygrain-v0.2.3\segmenteverygrain\segmenteverygrain.py in sam_segmentation(sam, image, image_pred, coords, labels, min_area, plot_image, remove_edge_grains, remove_large_objects) 806 ax.imshow(image) 807 plot_image_w_colorful_grains(image, all_grains, ax, cmap="Paired") --> 808 plot_grain_axes_and_centroids( 809 all_grains, labels, ax, linewidth=1, markersize=10 810 )
~\Dropbox\University\Frosinone\Sezioni_Sottili\segmentverygrain\segmenteverygrain-v0.2.3\segmenteverygrain\segmenteverygrain.py in plot_grain_axes_and_centroids(all_grains, labels, ax, linewidth, markersize) 1748 regions = regionprops(labels.astype("int")) 1749 for ind in range(len(all_grains) - 1): -> 1750 y0, x0 = regions[ind].centroid 1751 orientation = regions[ind].orientation 1752 x1 = x0 + np.cos(orientation) * 0.5 * regions[ind].minor_axis_length
IndexError: list index out of range
Hi Marco,
I assume you are using the latest release (installed with pip) - is that correct?
If you send me an image where this happens, I can try to figure out what's going on.
You could also try using the development version which has now a slightly different but better and faster editing interface.
Zoltan
Hi Zoltan, yes, I just downloaded the package so I should have the last version - this is the image that I was testing https://www.dropbox.com/scl/fi/puoavt2r6wycmcbbab6ct/AN003b_crop.png?rlkey=681yhtvfsduszjmu2cch5590n&dl=0 I noticed that if I change the dbs_max_dist to 10 the issue does not occur Thanks! Marco
Hi @marcopatacci-dotcom - I think I have fixed the bug. Let me know if it works. This looks like a pretty challenging image - you will probably need to do some finetuning if you want to run segmenteverygrain on many images like this.