# How to extract frame from Multiframe Image/FrameSet? (JAVA)

**URL:** https://discourse.itk.org/t/how-to-extract-frame-from-multiframe-image-frameset-java/6288
**Category:** Beginner Questions
**Tags:** multiframe, extract, java
**Created:** [November 7, 2023, 4:51am UTC](https://discourse.itk.org/t/how-to-extract-frame-from-multiframe-image-frameset-java/6288 "2023-11-07T04:51:40Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Salu\_Ramos](https://discourse.itk.org/user_avatar/discourse.itk.org/salu_ramos/32/3619_2.png) [@Salu\_Ramos](https://discourse.itk.org/u/Salu_Ramos)
#### Post date: [November 7, 2023, 4:51am UTC](https://discourse.itk.org/t/how-to-extract-frame-from-multiframe-image-frameset-java/6288/1 "2023-11-07T04:51:40Z")

</div>

I have a multiframe instance loaded with ImageSeriesReader, and i want to know how am i supposed to extract a frame from the result Image/frameSet.

The below script was working fine for singleframe instances loaded as an Image/frameSet:

```auto
public static Image axisSlice (Image volume, long[] sliceSize, int[] sliceIndex) {
        VectorUInt32 vectorSize = new VectorUInt32(sliceSize);
        VectorInt32 vectorIndex = new VectorInt32(sliceIndex);
        return SimpleITK.extract(volume, vectorSize, vectorIndex);
    }

```

i’m working with simpleitk java version.

---

<div class="post-metadata">

### Author: ![zivy](https://discourse.itk.org/user_avatar/discourse.itk.org/zivy/32/1726_2.png) [@zivy](https://discourse.itk.org/u/zivy)
#### Post date: [November 7, 2023, 1:45pm UTC](https://discourse.itk.org/t/how-to-extract-frame-from-multiframe-image-frameset-java/6288/2 "2023-11-07T13:45:28Z")

</div>

Hello @Salu_Ramos,

Not sure what is the problem you are encountering. I’m guessing that you are working with a 4D image and want to extract one of the 3D volumes? The extract method is the filter to use. For the specifics see [the filter’s documentation](https://simpleitk.org/doxygen/latest/html/classitk_1_1simple_1_1ExtractImageFilter.html#details) which shows how to extract the 3D volume from the 4D one.

If this isn’t the case, please provide additional details, the input image sizes and what you want to extract.

---

<div class="post-metadata">

### Author: ![Salu\_Ramos](https://discourse.itk.org/user_avatar/discourse.itk.org/salu_ramos/32/3619_2.png) [@Salu\_Ramos](https://discourse.itk.org/u/Salu_Ramos)
#### Post date: [November 7, 2023, 5:58pm UTC](https://discourse.itk.org/t/how-to-extract-frame-from-multiframe-image-frameset-java/6288/3 "2023-11-07T17:58:08Z")

</div>

> [@zivy](#):
>
> o extract the 3D volume from the 4D

Hi @zivy,

you are right, i’m working with 4D Image, the size is [512, 512, 85, 1]. I want a 512x512 extraction, so i need a function that receives de Image and the Index (index is z-axis). Something like this below?

```auto
public static Image axisSlice (Image pixeldata, int index) {
        ExtractImageFilter filter = new ExtractImageFilter();
        filter.setIndex(###int vector here###);
        return filter.execute(pixeldata);
    }

```

What goes inside setIndex? Thankss

---

<div class="post-metadata">

### Author: ![zivy](https://discourse.itk.org/user_avatar/discourse.itk.org/zivy/32/1726_2.png) [@zivy](https://discourse.itk.org/u/zivy)
#### Post date: [November 7, 2023, 6:42pm UTC](https://discourse.itk.org/t/how-to-extract-frame-from-multiframe-image-frameset-java/6288/4 "2023-11-07T18:42:43Z")

</div>

Hello @Salu_Ramos,

Pseudo-code, something like:

```auto
extract_size = [512,512,0,0] # first two entries are the pixeldata image size and rest are zero
index = [0,0,index,0] 
filter.SetSize(extract_size)
filter.SetIndex(index)

```

---

<div class="post-metadata">

### Author: ![Salu\_Ramos](https://discourse.itk.org/user_avatar/discourse.itk.org/salu_ramos/32/3619_2.png) [@Salu\_Ramos](https://discourse.itk.org/u/Salu_Ramos)
#### Post date: [November 7, 2023, 7:34pm UTC](https://discourse.itk.org/t/how-to-extract-frame-from-multiframe-image-frameset-java/6288/5 "2023-11-07T19:34:23Z")

</div>

thank you very much! works perfectly
