# Reverse search volume in sequence volume and get frame number

**URL:** <https://discourse.slicer.org/t/reverse-search-volume-in-sequence-volume-and-get-frame-number/7845>\
**Category:** Development\
**Created:** [August 1, 2019, 9:45pm UTC](https://discourse.slicer.org/t/reverse-search-volume-in-sequence-volume-and-get-frame-number/7845 "2019-08-01T21:45:06Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![che85](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/che85/32/636_2.png) [@che85](https://discourse.slicer.org/u/che85)\
**Post date:** [August 1, 2019, 9:45pm UTC](https://discourse.slicer.org/t/reverse-search-volume-in-sequence-volume-and-get-frame-number/7845/1 "2019-08-01T21:45:06Z")

</div>

Hi,

I got an extracted frame (volume) from a sequence and I would not like to go back and figure out which frame it originally was. Is there a way to search a sequence for a given volume and extract the original frame number?

Szenario A (creation):

1. user loads a sequence into 3D Slicer
2. user extracts frame
3. user saves MRML scene
4. repeat 1-3 on hundreds of datasets

Szenario B (reverse search):

1. user loads MRML scene
2. user puts sequence and extracted frame next to each other and compares frame by frame visually

I would want to automate Szenario B somehow. Is this possible?

Best,  
Christian

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [August 2, 2019, 3:26am UTC](https://discourse.slicer.org/t/reverse-search-volume-in-sequence-volume-and-get-frame-number/7845/2 "2019-08-02T03:26:24Z")

</div>

This looks very similar to what is implemented in the [utrasound annotation export module](https://github.com/SlicerIGT/UsAnnotationExport), which generates training data for deep-learning-based segmentation. Probably the same method can be used to link extracted frames to the original frames.

The module might be usable in your workflow as is, or with small modifications.

@ungi

---

<div class="post-metadata">

**Author:** ![ungi](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/ungi/32/78573_2.png) [@ungi](https://discourse.slicer.org/u/ungi)\
**Post date:** [August 2, 2019, 3:40am UTC](https://discourse.slicer.org/t/reverse-search-volume-in-sequence-volume-and-get-frame-number/7845/3 "2019-08-02T03:40:41Z")

</div>

Yes. Look at how the SingleSliceSegmentation module in the link Andras provided. It hides the original frame number in the segmentation as a MRML node attribute. However, if you just want to compare the segmentation with the original image, there is a more convenient method that does not require a custom module. You can create another sequence and save there both the segmentation and the original image. That will be a copy, so that is not super storage efficient. But it works in Slicer as is.

---

<div class="post-metadata">

**Author:** ![che85](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/che85/32/636_2.png) [@che85](https://discourse.slicer.org/u/che85)\
**Post date:** [August 2, 2019, 2:51pm UTC](https://discourse.slicer.org/t/reverse-search-volume-in-sequence-volume-and-get-frame-number/7845/4 "2019-08-02T14:51:42Z")

</div>

Thanks for the replies.

I think, it’s a bit more complicated when I go back to old mrmlScenes where I only have the original sequence and an extracted frame as a scalar volume.

Basically, I want to look at those old cases where I don’t have any information saved anywhere about which frame was extracted.

---

<div class="post-metadata">

**Author:** ![che85](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/che85/32/636_2.png) [@che85](https://discourse.slicer.org/u/che85)\
**Post date:** [August 2, 2019, 3:22pm UTC](https://discourse.slicer.org/t/reverse-search-volume-in-sequence-volume-and-get-frame-number/7845/5 "2019-08-02T15:22:48Z")

</div>

I think another way would be to use `Subtract Scalar Volumes` with 0 interpolation iterating over every frame of the Sequence subtracting the scalar volume I am looking for.

The resulting volume would (if it is the frame we are looking for) have only pixel values 0.

This wouldn’t work though if the scalar volume was modified after extraction.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [August 2, 2019, 5:28pm UTC](https://discourse.slicer.org/t/reverse-search-volume-in-sequence-volume-and-get-frame-number/7845/6 "2019-08-02T17:28:00Z")

</div>

You can compute histogram of the difference and if most of the voxels have no or small difference then most likely the volumes match.
