# 4D volume sequences cropping

**URL:** <https://discourse.slicer.org/t/4d-volume-sequences-cropping/4878>\
**Category:** Support\
**Tags:** sequences\
**Created:** [November 26, 2018, 10:14pm UTC](https://discourse.slicer.org/t/4d-volume-sequences-cropping/4878 "2018-11-26T22:14:16Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![M\_pavi](https://avatars.discourse-cdn.com/v4/letter/m/54ee81/32.png) [@M\_pavi](https://discourse.slicer.org/u/M_pavi)\
**Post date:** [November 26, 2018, 10:14pm UTC](https://discourse.slicer.org/t/4d-volume-sequences-cropping/4878/1 "2018-11-26T22:14:16Z")

</div>

I have been working on 4D volume sequences (.nrrd format) on 3D slicer. I use segmentation editor to crop some parts where after I crop some parts I wanted to save it as another new volume. But after saving this I couldn’t open it as a 4D volume. It shows as a 3D volume without any 4D supports.

---

<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:** [November 27, 2018, 12:00am UTC](https://discourse.slicer.org/t/4d-volume-sequences-cropping/4878/2 "2018-11-27T00:00:19Z")

</div>

> [@M\_pavi](#):
>
> I use segmentation editor to crop some parts where after I crop some parts

Segment editor can be used to create and edit segments. How did you use it to crop something? Do you mean you masked out certain region of an image volume?

> [@M\_pavi](#):
>
> I wanted to save it as another new volume

Would you like to mask out a certain region in all frames of a volume sequence (4D volume) and save the result as a volume sequence?

---

<div class="post-metadata">

**Author:** ![M\_pavi](https://avatars.discourse-cdn.com/v4/letter/m/54ee81/32.png) [@M\_pavi](https://discourse.slicer.org/u/M_pavi)\
**Post date:** [November 27, 2018, 12:04am UTC](https://discourse.slicer.org/t/4d-volume-sequences-cropping/4878/3 "2018-11-27T00:04:26Z")

</div>

Yes, I masked out certain region of volume sequence.I might be wrong. What I need to do eliminate some area from my 4D volume and save the results as 4D volume (volume sequence )

---

<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:** [November 27, 2018, 12:30am UTC](https://discourse.slicer.org/t/4d-volume-sequences-cropping/4878/4 "2018-11-27T00:30:19Z")

</div>

You need to create a new 4D volume sequence and go through your 4D volume and apply cropping to each frame:

Create a new 4D volume:

- In Segment Editor module, apply masking to the current frame of your volume (it’ll create a volume such as “CTP-cardio masked”)
- Go to “Sequence Browser” module, in Synchronized nodes section, click “+” icon =\> this creates a new sequence (while “Create new sequence” is selected on the left) and a new row appears in the table below
- In that new row, set the “Proxy node” to the masked volume (e.g., “CTP-cardio masked”) to associate the 3D volume with the 4D sequence, and check “Save changes” checkbox to automatically save modifications (when you mask the volume, the result will be saved in the sequence)

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/1/4/14715ecc148495f66be9fffbd6e8f0bca8c22bb8.png)

Apply masking to each frame:

- Go to Segment Editor module
- Click on Mask volume effect
- Click Apply
- Go to next frame by hitting Ctrl + Shift + Right-arrow key
- Click Apply
- … repeat the last 2 steps until you reach the end of your sequence

I know that the last two steps may be tedious (especially if you have hundreds of frames), but it can be automated using Python scripting. Let me know if you need this and I can describe how to do that.

---

<div class="post-metadata">

**Author:** ![J.vd.Zee](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/j.vd.zee/32/15064_2.png) [@J.vd.Zee](https://discourse.slicer.org/u/J.vd.Zee)\
**Post date:** [June 17, 2022, 9:58am UTC](https://discourse.slicer.org/t/4d-volume-sequences-cropping/4878/5 "2022-06-17T09:58:32Z")

</div>

Hi!  
This problem is still relevant and I wonder if any progress on this topic has been carried out.  
I have a live US stream to Slicer via the Plus Server and openIGTlink. However, my stream contains the whole US interface including all not useful aspects as visible in the picture below. The machine learning module is now performing the algorithm on this window instead of the US images alone. Is there any possibility to mask or crop the input signal in a live manner before getting a sequence or giving it to the live Unet algorithm?

Thanks!

 ![US_stream](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/e/4/e4e78377a89c7b3eca1c8cfcb3317471c6f806c1.png)

---

<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:** [June 17, 2022, 2:28pm UTC](https://discourse.slicer.org/t/4d-volume-sequences-cropping/4878/6 "2022-06-17T14:28:55Z")

</div>

You can crop 4D volume sequences using `Crop volume sequence` module. Let us know if you have any questions about how to use it.

---

<div class="post-metadata">

**Author:** ![J.vd.Zee](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/j.vd.zee/32/15064_2.png) [@J.vd.Zee](https://discourse.slicer.org/u/J.vd.Zee)\
**Post date:** [June 21, 2022, 10:54am UTC](https://discourse.slicer.org/t/4d-volume-sequences-cropping/4878/7 "2022-06-21T10:54:22Z")

</div>

Thanks for your answer!

Is it also possible to crop the input signal in the _PuDeviceSet\_Server\_MmfVideoCapture.xml_ instead by just adding a few lines of code? That would be perfect as I am only interested in the

 ![Cropping_input](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/8/9/89905660f40b8854220528eb462fa67c96759dc7.jpeg)

---

<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:** [June 21, 2022, 3:31pm UTC](https://discourse.slicer.org/t/4d-volume-sequences-cropping/4878/8 "2022-06-21T15:31:24Z")

</div>

Yes, you can clip the image to the relevant region by setting `ClipRectangleOrigin` and `ClipRectangleSize` parameters in the Plus configuration file - see specification [here](http://perk-software.cs.queensu.ca/plus/doc/nightly/user/DeviceMicrosoftMediaFoundation.html).

---

<div class="post-metadata">

**Author:** ![J.vd.Zee](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/j.vd.zee/32/15064_2.png) [@J.vd.Zee](https://discourse.slicer.org/u/J.vd.Zee)\
**Post date:** [June 22, 2022, 8:34am UTC](https://discourse.slicer.org/t/4d-volume-sequences-cropping/4878/9 "2022-06-22T08:34:42Z")

</div>

Thanks for your answer. You really helped me out!  
It worked with just adding a line of code 🙂

A little remark for the specification you sent me.  
For two-dimensional input data the third component _must_ be ommitted instead of _may_ be ommitted in my case.

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/4/9/49f97c8399fe94d2721a435a509c05a82d2f4646.png)

---

<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:** [June 22, 2022, 1:06pm UTC](https://discourse.slicer.org/t/4d-volume-sequences-cropping/4878/10 "2022-06-22T13:06:48Z")

</div>

Thanks for confirming. I’ve updated the language around “may be” (changed to “may need to be”, as I’m not sure if it “must be” omitted for every devices).
