

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 获取影像集像素数据
<a name="get-image-frame"></a>

影像帧是[影像集](getting-started-concepts.md#concept-image-frame)中存在的用于构成 2D 医学影像的像素数据。[使用`GetImageFrame`操作检索中给定图像的 HTJ2 K 编码或原生 JPEG 2000 无损图像帧。](getting-started-concepts.md#concept-image-set) HealthImaging以下菜单提供了 AWS CLI 和的代码示例 AWS SDKs。有关更多信息，请参阅 *AWS HealthImaging API 参考[https://docs.aws.amazon.com/healthimaging/latest/APIReference/API_GetImageFrame.html](https://docs.aws.amazon.com/healthimaging/latest/APIReference/API_GetImageFrame.html)*中的。

**注意**  
使用`GetImageFrame`操作时，请记住以下几点：  
在[导入](importing-imaging-data.md)过程中， HealthImaging 保留某些传输语法的编码，并将其他语法转码为 HTJ2 K 无损（默认）或 JPEG 2000 Lossless。该`GetImageFrame`操作以实例的存储传输语法返回图像框架。检索期间不进行任何转码，以确保检索延迟最小。在图像查看器中查看图像之前，可能需要对图像帧进行解码，具体取决于传输语法。有关更多信息，请参阅[支持的传输语法](supported-transfer-syntaxes.md)和[图像帧解码库](reference-libraries.md)。
[对于存储在一个或多个 HealthImaging 以 MPEG 系列传输语法（包括 MPEG-4 AVC/H.264 and HEVC/H .265）中编码的图像帧的实例 MPEG2，该`GetImageFrame`操作将以存储的传输语法返回视频对象。](supported-transfer-syntaxes.md)
图像帧的传输语法在`Content-Type HTTP`标题响应元素中指定。例如，以 HTJ2 K 编码的图像帧将具有`Content-Type: image/jph header`。有关更多信息，请参阅 *AWS HealthImaging API 参考[https://docs.aws.amazon.com/healthimaging/latest/APIReference/API_GetImageFrame.html](https://docs.aws.amazon.com/healthimaging/latest/APIReference/API_GetImageFrame.html)*中的。
您还可以使用`GetDICOMInstanceFrames` DICOMweb 服务的表示形式为 DICOMweb兼容的查看器和应用程序检索 DICOM 实例帧（`multipart`请求）。 HealthImaging有关更多信息，请参阅 [从中获取 DICOM 实例帧 HealthImaging](dicomweb-retrieve-instance-frames.md)。

**获取图像集像素数据**  
根据您对 AWS 的访问偏好选择菜单 HealthImaging。

## AWS 控制台
<a name="code-example-console-image-set-get-pixel-data"></a>

**注意**  
由于 AWS 管理控制台未提供影像查看器，因此必须以编程方式对影像帧进行解码和访问。  
有关解码和查看影像帧的更多信息，请参阅 [图像帧解码库](reference-libraries.md)。

## AWS CLI 和 SDKs
<a name="code-example-cli-sdk-image-set-get-pixel-data"></a>

------
#### [ C\$1\$1 ]

**SDK for C\$1\$1**  

```
//! Routine which downloads an AWS HealthImaging image frame.
/*!
  \param dataStoreID: The HealthImaging data store ID.
  \param imageSetID: The image set ID.
  \param frameID: The image frame ID.
  \param jphFile: File to store the downloaded frame.
  \param clientConfig: Aws client configuration.
  \return bool: Function succeeded.
*/
bool AwsDoc::Medical_Imaging::getImageFrame(const Aws::String &dataStoreID,
                                            const Aws::String &imageSetID,
                                            const Aws::String &frameID,
                                            const Aws::String &jphFile,
                                            const Aws::Client::ClientConfiguration &clientConfig) {
    Aws::MedicalImaging::MedicalImagingClient client(clientConfig);

    Aws::MedicalImaging::Model::GetImageFrameRequest request;
    request.SetDatastoreId(dataStoreID);
    request.SetImageSetId(imageSetID);

    Aws::MedicalImaging::Model::ImageFrameInformation imageFrameInformation;
    imageFrameInformation.SetImageFrameId(frameID);
    request.SetImageFrameInformation(imageFrameInformation);

    Aws::MedicalImaging::Model::GetImageFrameOutcome outcome = client.GetImageFrame(
            request);

    if (outcome.IsSuccess()) {
        std::cout << "Successfully retrieved image frame." << std::endl;
        auto &buffer = outcome.GetResult().GetImageFrameBlob();

        std::ofstream outfile(jphFile, std::ios::binary);
        outfile << buffer.rdbuf();
    }
    else {
        std::cout << "Error retrieving image frame." << outcome.GetError().GetMessage()
                  << std::endl;

    }

    return outcome.IsSuccess();
}
```
+  有关 API 的详细信息，请参阅 *适用于 C\$1\$1 的 AWS SDK API 参考[GetImageFrame](https://docs.aws.amazon.com/goto/SdkForCpp/medical-imaging-2023-07-19/GetImageFrame)*中的。
 还有更多相关信息 GitHub。在 [AWS 代码示例存储库](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/cpp/example_code/medical-imaging/#code-examples)中查找完整示例，了解如何进行设置和运行。

------
#### [ CLI ]

**AWS CLI**  
**获取图像集像素数据**  
以下 `get-image-frame` 代码示例获取图像帧。  

```
aws medical-imaging get-image-frame \
    --datastore-id "12345678901234567890123456789012" \
    --image-set-id "98765412345612345678907890789012" \
    --image-frame-information imageFrameId=3abf5d5d7ae72f80a0ec81b2c0de3ef4 \
    imageframe.jph
```
注意：此代码示例不包括输出，因为该 GetImageFrame 操作将像素数据流返回到 imageframe.jph 文件。有关解码和查看图像帧的信息，请参阅 HTJ2 K 解码库。  
有关更多信息，请参阅《*AWS HealthImaging 开发者指南》*中的[获取图像集像素数据](https://docs.aws.amazon.com/healthimaging/latest/devguide/get-image-frame.html)。  
+  有关 API 的详细信息，请参阅*AWS CLI 命令参考[GetImageFrame](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/medical-imaging/get-image-frame.html)*中的。

------
#### [ Java ]

**适用于 Java 的 SDK 2.x**  

```
        public static void getMedicalImageSetFrame(MedicalImagingClient medicalImagingClient,
                        String destinationPath,
                        String datastoreId,
                        String imagesetId,
                        String imageFrameId) {

                try {
                        GetImageFrameRequest getImageSetMetadataRequest = GetImageFrameRequest.builder()
                                        .datastoreId(datastoreId)
                                        .imageSetId(imagesetId)
                                        .imageFrameInformation(ImageFrameInformation.builder()
                                                        .imageFrameId(imageFrameId)
                                                        .build())
                                        .build();
                        medicalImagingClient.getImageFrame(getImageSetMetadataRequest,
                                        FileSystems.getDefault().getPath(destinationPath));

                        System.out.println("Image frame downloaded to " + destinationPath);
                } catch (MedicalImagingException e) {
                        System.err.println(e.awsErrorDetails().errorMessage());
                        System.exit(1);
                }
        }
```
+  有关 API 的详细信息，请参阅 *AWS SDK for Java 2.x API 参考[GetImageFrame](https://docs.aws.amazon.com/goto/SdkForJavaV2/medical-imaging-2023-07-19/GetImageFrame)*中的。
 还有更多相关信息 GitHub。在 [AWS 代码示例存储库](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/javav2/example_code/medicalimaging#code-examples)中查找完整示例，了解如何进行设置和运行。

------
#### [ JavaScript ]

**适用于 JavaScript (v3) 的软件开发工具包**  

```
import { GetImageFrameCommand } from "@aws-sdk/client-medical-imaging";
import { medicalImagingClient } from "../libs/medicalImagingClient.js";

/**
 * @param {string} imageFrameFileName - The name of the file for the HTJ2K-encoded image frame.
 * @param {string} datastoreID - The data store's ID.
 * @param {string} imageSetID - The image set's ID.
 * @param {string} imageFrameID - The image frame's ID.
 */
export const getImageFrame = async (
  imageFrameFileName = "image.jph",
  datastoreID = "DATASTORE_ID",
  imageSetID = "IMAGE_SET_ID",
  imageFrameID = "IMAGE_FRAME_ID",
) => {
  const response = await medicalImagingClient.send(
    new GetImageFrameCommand({
      datastoreId: datastoreID,
      imageSetId: imageSetID,
      imageFrameInformation: { imageFrameId: imageFrameID },
    }),
  );
  const buffer = await response.imageFrameBlob.transformToByteArray();
  writeFileSync(imageFrameFileName, buffer);

  console.log(response);
  // {
  //     '$metadata': {
  //         httpStatusCode: 200,
  //         requestId: 'e4ab42a5-25a3-4377-873f-374ecf4380e1',
  //         extendedRequestId: undefined,
  //         cfId: undefined,
  //         attempts: 1,
  //         totalRetryDelay: 0
  //     },
  //     contentType: 'application/octet-stream',
  //     imageFrameBlob: <ref *1> IncomingMessage {}
  // }
  return response;
};
```
+  有关 API 的详细信息，请参阅 *适用于 JavaScript 的 AWS SDK API 参考[GetImageFrame](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/medical-imaging/command/GetImageFrameCommand)*中的。
 还有更多相关信息 GitHub。在 [AWS 代码示例存储库](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/javascriptv3/example_code/medical-imaging#code-examples)中查找完整示例，了解如何进行设置和运行。

------
#### [ Python ]

**适用于 Python 的 SDK（Boto3）**  

```
class MedicalImagingWrapper:
    def __init__(self, health_imaging_client):
        self.health_imaging_client = health_imaging_client


    def get_pixel_data(
        self, file_path_to_write, datastore_id, image_set_id, image_frame_id
    ):
        """
        Get an image frame's pixel data.

        :param file_path_to_write: The path to write the image frame's HTJ2K encoded pixel data.
        :param datastore_id: The ID of the data store.
        :param image_set_id: The ID of the image set.
        :param image_frame_id: The ID of the image frame.
        """
        try:
            image_frame = self.health_imaging_client.get_image_frame(
                datastoreId=datastore_id,
                imageSetId=image_set_id,
                imageFrameInformation={"imageFrameId": image_frame_id},
            )
            with open(file_path_to_write, "wb") as f:
                for chunk in image_frame["imageFrameBlob"].iter_chunks():
                    if chunk:
                        f.write(chunk)
        except ClientError as err:
            logger.error(
                "Couldn't get image frame. Here's why: %s: %s",
                err.response["Error"]["Code"],
                err.response["Error"]["Message"],
            )
            raise
```
以下代码实例化对象。 MedicalImagingWrapper   

```
    client = boto3.client("medical-imaging")
    medical_imaging_wrapper = MedicalImagingWrapper(client)
```
+  有关 API 的详细信息，请参阅适用[GetImageFrame](https://docs.aws.amazon.com/goto/boto3/medical-imaging-2023-07-19/GetImageFrame)于 *Python 的AWS SDK (Boto3) API 参考*。
 还有更多相关信息 GitHub。在 [AWS 代码示例存储库](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/python/example_code/medical-imaging#code-examples)中查找完整示例，了解如何进行设置和运行。

------
#### [ SAP ABAP ]

**适用于 SAP ABAP 的 SDK**  

```
    TRY.
        " iv_datastore_id = '1234567890123456789012345678901234567890'
        " iv_image_set_id = '1234567890123456789012345678901234567890'
        " iv_image_frame_id = '1234567890123456789012345678901234567890'
        oo_result = lo_mig->getimageframe(
          iv_datastoreid = iv_datastore_id
          iv_imagesetid = iv_image_set_id
          io_imageframeinformation = NEW /aws1/cl_migimageframeinfmtion(
            iv_imageframeid = iv_image_frame_id ) ).
        DATA(lv_frame_blob) = oo_result->get_imageframeblob( ).
        MESSAGE 'Image frame retrieved.' TYPE 'I'.
      CATCH /aws1/cx_migaccessdeniedex.
        MESSAGE 'Access denied.' TYPE 'I'.
      CATCH /aws1/cx_migconflictexception.
        MESSAGE 'Conflict error.' TYPE 'I'.
      CATCH /aws1/cx_miginternalserverex.
        MESSAGE 'Internal server error.' TYPE 'I'.
      CATCH /aws1/cx_migresourcenotfoundex.
        MESSAGE 'Image frame not found.' TYPE 'I'.
      CATCH /aws1/cx_migthrottlingex.
        MESSAGE 'Request throttled.' TYPE 'I'.
      CATCH /aws1/cx_migvalidationex.
        MESSAGE 'Validation error.' TYPE 'I'.
    ENDTRY.
```
+  有关 API 的详细信息，请参阅适用[GetImageFrame](https://docs.aws.amazon.com/sdk-for-sap-abap/v1/api/latest/index.html)于 S *AP 的AWS SDK ABAP API 参考*。
 还有更多相关信息 GitHub。在 [AWS 代码示例存储库](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/sap-abap/services/mig#code-examples)中查找完整示例，了解如何进行设置和运行。

------

**示例可用性**  
找不到所需的内容？ 使用本页右侧边栏上的 “**提供反馈**” 链接请求代码示例。