dicom 태그를 보려면 C#에서 mDCM을 사용하고 있지만 픽셀 데이터를 비트 맵으로 변환하고 결국 JPG 파일로 변환하려고합니다. 주제에 대한 mDCM Google 그룹의 모든 게시물을 읽었으며 모든 코드 예제가 작동하지 않거나 중요한 코드 라인이 누락되었습니다. 내가 작업하고있는 이미지는 16 비트 모노크롬 1 (이것은 언급 된 형식이지만 실제로는 16 비트 회색조 임)입니다. 비트 맵으로 픽셀 데이터를 변환하기 위해 LockBits, SetPixel 및 안전하지 않은 코드를 사용하려고 시도했지만 모든 시도가 실패합니다. 누구든지이 작업을 수행 할 수있는 코드가 있습니까?DICOM 파일에서 JPG 내보내기 mDCM으로
여기와 setPixel를 사용하여 내 최신 시도 :
DcmElement pixelData = this.currentFileFormat.Dataset.GetElement(new DcmTag(DcmConstTags.PixelData));
ushort[] pixels = this.currentPixelData.GetFrameDataU16(0);
this.currentImage = new Bitmap(this.currentPixelData.ImageWidth, this.currentPixelData.ImageHeight, PixelFormat.Format16bppRgb555);
int resample = (int)Math.Pow(2, (this.currentPixelData.BitsStored - 8));
int pxCounter = 0;
int min = ushort.MaxValue;
int max = 0;
for (int c = 0; c < this.currentPixelData.ImageHeight; c++)
{
for (int r = 0; r < this.currentPixelData.ImageWidth; r++)
{
ushort pxColor = pixels[pxCounter];
int temp = 255 - (pxColor/resample);
if (temp < min) min = temp;
if (temp > max) max = temp;
this.currentImage.SetPixel(r, c, Color.FromArgb(temp, temp, temp));
pxCounter++;
}
}
업데이트 : LockBits 및 Marshal.Copy를 사용하여 가까이 입수했습니다하지만 이미지 대신 회색조의 색상의 무지개에서 제공 .
추신 : 미리
byte[] pixels = this.currentPixelData.GetFrameDataU8(frameIndex);
this.currentImage = new Bitmap(this.currentPixelData.ImageWidth, this.currentPixelData.ImageHeight, PixelFormat.Format16bppRgb555);
BitmapData bitmapData = this.currentImage.LockBits(new Rectangle(0, 0, this.currentImage.Width, this.currentImage.Height), ImageLockMode.ReadWrite, this.currentImage.PixelFormat);
System.Runtime.InteropServices.Marshal.Copy(pixels, 0, bitmapData.Scan0, this.currentImage.Width * this.currentImage.Height * 2);
this.currentImage.UnlockBits(bitmapData);
감사 : 그래서 내가 RBG 형식으로 그레이 스케일 데이터를 변환하는 방법이 필요합니다 같은데요 누군가 ClearCanvas와 같은 다른 것을 시도하기 전에 mDCM이 내 필요에 맞는 유일한 라이브러리라는 것을 알고 ClearCanvas는 내가해야 할 일에 너무 팽창되어 있습니다.
회색 음영에 대한 부분이 추가되었습니다. LeadTools 구매에 관심이 없습니다. 코드가 필요합니다. –
다음 코드를 사용하여 LockBits 및 Marshal.Copy를 사용하여 추가로 얻을 수 있지만 회색 음영 대신 무지개 색상으로 표시됩니다. byte [] pixels = currentPixelData.GetFrameDataU8 (frameIndex); currentImage = 새로운 비트 맵 (width, height, PixelFormat.Format16bppRgb555); BitmapData bitmapData = currentImage.LockBits (새 Rectangle (0, 0, width, height), ImageLockMode.ReadWrite, currentImage.PixelFormat); System.Runtime.InteropServices.Marshal.Copy (pixels, 0, bitmapData.Scan0, width * height * 2); currentImage.UnlockBits (bitmapData); –