2014-05-01 9 views
0

DICOM 파일에서 원시 픽셀 데이터를 180도 회전하려고합니다 (또는 뒤집기). 그러나 이미지를 올바르게 뒤집어 버렸습니다. 픽셀 데이터를 파일에 다시 쓰면 (이 경우 DICOM 파일 임) 이미지가 표시됩니다. 이미지의 최종 출력이 올바르지 않습니다.이미지의 원시 픽셀 데이터를 180도 회전하십시오.

다음은 180/미러를 뒤집어 쓰려고하는 이미지 샘플입니다.

 string file = @"adicomfile.dcm"; 
     DicomFile df = new DicomFile(); 
     df.Load(file); 

      // Get the amount of bits per pixel from the DICOM header. 
     int bitsPerPixel = df.DataSet[DicomTags.BitsAllocated].GetInt32(0, 0); 

      // Get the raw pixel data from the DICOM file. 
     byte[] bytes = df.DataSet[DicomTags.PixelData].Values as byte[]; 

        // Get the width and height of the image. 
     int width = df.DataSet[DicomTags.Columns].GetInt32(0, 0); 
     int height = df.DataSet[DicomTags.Rows].GetInt32(0, 0); 

     byte[] original = bytes; 
     byte[] mirroredPixels = new byte[width * height * (bitsPerPixel/8)]; 

     width *= (bitsPerPixel/8); 

        // The mirroring/image flipping. 
     for (int i = 0; i < original.Length; i++) 
     { 
      int mod = i % width; 
      int x = ((width - mod - 1) + i) - mod; 

      mirroredPixels[i] = original[x]; 
     } 

     df.DataSet[DicomTags.PixelData].Values = mirroredPixels; 

     df.Save(@"flippedicom.dcm", DicomWriteOptions.Default); 

그리고 여기 내 출력 (잘못된)이있다 :

enter image description here

는 여기가 반전을 수행하는 데 사용하고 코드입니다. 흰색과 왜곡이 원하는 출력이 아닙니다.

enter image description here

나는 단지 파일 자체에 포함 된 픽셀 데이터를 조작하기 위해 노력하고있어하지만이 문제가되지해야 클리어 캔버스 (ClearCanvas) DICOM 라이브러리를 사용하고 있습니다.

원하는 출력은 원본처럼 보이지만 뒤집 으면 180/미러링됩니다.

일부 도움을 주시면 대단히 감사하겠습니다. 나는 최선의 검색을 시도했지만 아무 소용이 없습니다.

+0

테스트로 작은 이미지를 가져 와서 실제로 이동하는 바이트를 확인하십시오. – csharpwinphonexaml

+0

이미지가 올바른 모양이고 올바른 위치에 올바른 요소가 포함되어 있다는 사실은 수학이 정확하다는 것을 말해줍니다. 올바른 장소에 올바른 장소. 따라서 전체 픽셀을 움직이지 않는 것으로 의심해야합니다. 컬러 이미지 인 경우 빨간색 또는 녹색 또는 파란색 채널 만 움직이거나 제대로 투명성을 마스킹하지 않고 다시 추가하는 경우 일 수 있습니다. 수학은 정확한 위치를 제공하지만 원점에서 전체 픽셀을 가져 오지 않거나 뒤집힌 이미지에 전체 픽셀을 다시 쓰지 않습니다. –

+0

'bitsPerPixel'의 값은 무엇입니까 (그리고 이미지의 PhotometricInterpretation은 무엇입니까?)? 8보다 크면 바이트 배열 대신 int 배열이 필요합니다. –

답변

0

시간이 좀 걸렸지 만 자바 라이브러리의 메소드를 사용하여 문제를 해결했습니다. here 클래스를 볼 수 있습니다.

string file = @"adicomfile.dcm"; 
DicomFile df = new DicomFile(); 
df.Load(file); 

// Get the amount of bits per pixel from the DICOM header. 
int bitsPerPixel = df.DataSet[DicomTags.BitsAllocated].GetInt32(0, 0); 

// Get the raw pixel data from the DICOM file. 
byte[] bytes = df.DataSet[DicomTags.PixelData].Values as byte[]; 

// Get the width and height of the image. 
int width = df.DataSet[DicomTags.Columns].GetInt32(0, 0); 
int height = df.DataSet[DicomTags.Rows].GetInt32(0, 0); 

byte[] newBytes = new byte[height * width * (bitsPerPixel/8)]; 
int stride = bitsPerPixel/8; 

for (int y = 0; y < height; y++) 
{ 
     for (int x = 0; x < width * stride; x++) 
     { 
     newBytes[((height - y - 1) * (width * stride)) + x] = bytes[(y * (width * stride)) + x]; 
    } 
} 

// Set patient orientation. 
df.DataSet[DicomTags.PatientOrientation].Values = @"A\L"; 

// The pixel data of the DICOM file to the flipped/mirrored data. 
df.DataSet[DicomTags.PixelData].Values = mirroredPixels; 

// Save the DICOM file. 
df.Save(@"flippedicom.dcm", DicomWriteOptions.Default); 

출력이 정확하고 원본 픽셀 데이터를 다른 수정을 계속할 수있었습니다.

감사합니다.