最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

typescript - How to enable progressive loading of NIfTI images? - Stack Overflow

programmeradmin0浏览0评论

I am trying to display a NIfTI image in CornerstoneJS while progressively loading it from a backend URL. The backend exposes a URL to download the NIfTI file, and I want to visualize slices progressively while the file is being downloaded.

Currently, I am using @cornerstonejs/nifti-volume-loader like this:

import * as cornerstone from '@cornerstonejs/core';
import { createNiftiImageIdsAndCacheMetadata } from '@cornerstonejs/nifti-volume-loader';

...

let renderingEngine = ...;
let volumeId = ...;
let imageIds = await createNiftiImageIdsAndCacheMetadata({ url: niftiUrl });
let volume = await cornerstone.volumeLoader.createAndCacheVolume(volumeId, {
    imageIds: imageIds,
    progressiveRendering: true
});

volume.load(() => {
    cornerstone.setVolumesForViewports(
        renderingEngine,
        [{ volumeId }],
        [...],
    );
});

This works, but the entire NIfTI file needs to be downloaded before rendering. I want to progressively load and display slices as they arrive.

I found the @cmi-dair/nifti-stream library, which allows me to extract the header and receive one slice at a time while downloading. Here’s how I am handling the streaming:

import { NiftiExtension, NiftiHeader, NiftiStream } from '@cmi-dair/nifti-stream';

...

let response = await fetch(niftiUrl);
if (!response.body) {
    throw new Error('Failed to get response body');
}

let reader = new NiftiStream(response.body, {
    sliceDimension: 2,

    onHeader: async (header: NiftiHeader) => {
        ...
    },

    onExtension: (extension: NiftiExtension | null) => {
        ...
    },

    onSlice: (data: ArrayBuffer, indices: number[]) => {
        ...
    },

    onError: (error) => {
        console.error(error);
    }
});

await reader.start();

Now, how can I integrate this progressive slice loading with CornerstoneJS?

  • Do I need to register a new volume loader to handle the streaming slices?
  • Is there an alternative approach to achieve progressive rendering without waiting for the full file to download?
  • Can I manually update a StreamingImageVolume as slices arrive?

Any guidance on integrating @cmi-dair/nifti-stream with CornerstoneJS for progressive rendering would be highly appreciated!

发布评论

评论列表(0)

  1. 暂无评论