Skip to content

Commit 303d2ce

Browse files
authored
Merge pull request mlavik1#75 from vahpy/patch-2
Optimise Image Sequence Importer
2 parents 13abae6 + 9227bde commit 303d2ce

File tree

1 file changed

+7
-32
lines changed

1 file changed

+7
-32
lines changed

Assets/Scripts/Importing/ImageSequenceImporter.cs

Lines changed: 7 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ public VolumeDataset Import()
3030

3131
List<string> imagePaths = GetSortedImagePaths();
3232

33-
if (!ImageSetHasUniformDimensions(imagePaths))
34-
throw new IndexOutOfRangeException("Image sequence has non-uniform dimensions");
35-
3633
Vector3Int dimensions = GetVolumeDimensions(imagePaths);
3734
int[] data = FillSequentialData(dimensions, imagePaths);
3835
VolumeDataset dataset = FillVolumeDataset(data, dimensions);
@@ -60,34 +57,6 @@ private List<string> GetSortedImagePaths()
6057
return imagePaths;
6158
}
6259

63-
/// <summary>
64-
/// Checks if every image in the set has the same XY dimensions.
65-
/// </summary>
66-
/// <param name="imagePaths">The list of image paths to check.</param>
67-
/// <returns>True if at least one image differs from another.</returns>
68-
private bool ImageSetHasUniformDimensions(List<string> imagePaths)
69-
{
70-
bool hasUniformDimension = true;
71-
72-
Vector2Int previous, current;
73-
previous = GetImageDimensions(imagePaths[0]);
74-
75-
foreach (var path in imagePaths)
76-
{
77-
current = GetImageDimensions(path);
78-
79-
if (current.x != previous.x || current.y != previous.y)
80-
{
81-
hasUniformDimension = false;
82-
break;
83-
}
84-
85-
previous = current;
86-
}
87-
88-
return hasUniformDimension;
89-
}
90-
9160
/// <summary>
9261
/// Gets the XY dimensions of an image at the path.
9362
/// </summary>
@@ -142,6 +111,12 @@ private int[] FillSequentialData(Vector3Int dimensions, List<string> paths)
142111
byte[] bytes = File.ReadAllBytes(path);
143112
texture.LoadImage(bytes);
144113

114+
if (texture.width != dimensions.x || texture.height != dimensions.y)
115+
{
116+
Texture2D.DestroyImmediate(texture);
117+
throw new IndexOutOfRangeException("Image sequence has non-uniform dimensions");
118+
}
119+
145120
Color[] pixels = texture.GetPixels(); // Order priority: X -> Y -> Z
146121
int[] imageData = DensityHelper.ConvertColorsToDensities(pixels);
147122

@@ -177,4 +152,4 @@ private VolumeDataset FillVolumeDataset(int[] data, Vector3Int dimensions)
177152
return dataset;
178153
}
179154
}
180-
}
155+
}

0 commit comments

Comments
 (0)