|
24 | 24 | import org.janelia.alignment.ShortRenderer; |
25 | 25 | import org.janelia.alignment.Utils; |
26 | 26 | import org.janelia.alignment.destreak.SecondChannelStreakCorrector; |
| 27 | +import org.janelia.alignment.loader.DynamicMaskLoader; |
27 | 28 | import org.janelia.alignment.loader.ImageLoader; |
28 | 29 | import org.janelia.alignment.spec.ChannelSpec; |
29 | 30 | import org.janelia.alignment.spec.ResolvedTileSpecCollection; |
@@ -277,15 +278,24 @@ private String buildOutputPath(final Parameters clientParameters, final TileSpec |
277 | 278 | } |
278 | 279 |
|
279 | 280 | private void updateTileSpecWithCorrectedImage(final TileSpec tileSpec, final String imagePath) { |
280 | | - // Replace all channels with a single channel pointing to the corrected image |
281 | | - final List<ChannelSpec> allChannels = tileSpec.getAllChannels(); |
282 | | - allChannels.clear(); |
283 | | - |
284 | | - final ChannelSpec correctedChannel = new ChannelSpec(); |
285 | | - correctedChannel.putMipmap(0, new ImageAndMask(imagePath, null)); |
| 281 | + // Point the tile spec to the new image |
| 282 | + final ChannelSpec channelSpec = tileSpec.getAllChannels().get(0); |
| 283 | + ImageAndMask imageAndMask = channelSpec |
| 284 | + .getFirstMipmapImageAndMask(tileSpec.getTileId()) |
| 285 | + .copyWithImage(imagePath, null, null); |
| 286 | + |
| 287 | + // If the channel has a mask, ensure it is a dynamic mask and update the URL |
| 288 | + if (channelSpec.hasMask()) { |
| 289 | + if (! ImageLoader.LoaderType.DYNAMIC_MASK.equals(imageAndMask.getMaskLoaderType())) { |
| 290 | + throw new IllegalArgumentException("Channel " + channelSpec.getName() + |
| 291 | + " has a mask, but it is not a dynamic mask. Cannot update tile spec."); |
| 292 | + } |
286 | 293 |
|
287 | | - tileSpec.addChannel(correctedChannel); |
| 294 | + final DynamicMaskLoader.DynamicMaskDescription description = DynamicMaskLoader.parseUrl(imageAndMask.getMaskUrl()); |
| 295 | + imageAndMask = imageAndMask.copyWithMask(description.toString(), ImageLoader.LoaderType.DYNAMIC_MASK, null); |
| 296 | + } |
288 | 297 |
|
| 298 | + channelSpec.putMipmap(0, imageAndMask); |
289 | 299 | LOG.debug("updateTileSpecWithCorrectedImage: updated tile {} with corrected image at {}", |
290 | 300 | tileSpec.getTileId(), imagePath); |
291 | 301 | } |
|
0 commit comments