func DicomToImages(dicomReader io.Reader) ([]image.Image, error) {
	dcm, err := ioutil.ReadAll(dicomReader)
	if err != nil {
		return nil, err
	}

	p, err := dicom.NewParserFromBytes(dcm, nil)
	if err != nil {
		return nil, err
	}

	parsedData, err := bulkprocess.SafelyDicomParse(p, dicom.ParseOptions{
		DropPixelData: false,
	})

	if parsedData == nil || err != nil {
		return nil, fmt.Errorf("Error reading dicom")
	}

	var output []image.Image

	for _, elem := range parsedData.Elements {
		if elem.Tag == dicomtag.PixelData {
			data := elem.Value[0].(element.PixelDataInfo)

			for _, frame := range data.Frames {
				if frame.IsEncapsulated() {
					return nil, fmt.Errorf("Frame is encapsulated, which we did not expect")
				}

				//i := image.NewRGBA(image.Rect(0, 0, frame.NativeData.Cols, frame.NativeData.Rows))
				i := image.NewGray(image.Rect(0, 0, frame.NativeData.Cols, frame.NativeData.Rows))

				for j := 0; j < len(frame.NativeData.Data); j++ {
					// To the extent that I can tell, we are receiving 8-bit grayscale information.
					intensity := byte(frame.NativeData.Data[j][0])

					//i.SetRGBA(j%frame.NativeData.Cols, j/frame.NativeData.Rows, color.RGBA{R: intensity, B: intensity, G: intensity, A: 255})
					i.SetGray(j%frame.NativeData.Cols, j/frame.NativeData.Rows, color.Gray{intensity})
				}

				output = append(output, i)
			}

		}
	}

	return output, nil
}
// DicomToImage constructs native go Image types from the dicom images. Usually
// (perhaps always?) there will be just one image.
DicomToImage constructs native go Image types from the dicom images. Usually
(perhaps always?) there will be just one image.
// DicomToImage constructs native go Image types from the dicom images . Usually // ( perhaps always? ) there will be just one image .
func DicomToImages(dicomReader io.Reader) ([]image.Image, error) {
	dcm, err := ioutil.ReadAll(dicomReader)
	if err != nil {
		return nil, err
	}
	p, err := dicom.NewParserFromBytes(dcm, nil)
	if err != nil {
		return nil, err
	}
	parsedData, err := bulkprocess.SafelyDicomParse(p, dicom.ParseOptions{
		DropPixelData: false,
	})
	if parsedData == nil || err != nil {
		return nil, fmt.Errorf("Error reading dicom")
	}
	var output []image.Image
	for _, elem := range parsedData.Elements {
		if elem.Tag == dicomtag.PixelData {
			data := elem.Value[0].(element.PixelDataInfo)
			for _, frame := range data.Frames {
				if frame.IsEncapsulated() {
					return nil, fmt.Errorf("Frame is encapsulated, which we did not expect")
				}
				i := image.NewGray(image.Rect(0, 0, frame.NativeData.Cols, frame.NativeData.Rows))
				for j := 0; j < len(frame.NativeData.Data); j++ {
					intensity := byte(frame.NativeData.Data[j][0])
					i.SetGray(j%frame.NativeData.Cols, j/frame.NativeData.Rows, color.Gray{intensity})
				}
				output = append(output, i)
			}
		}
	}
	return output, nil
}
func DicomToImages ( dicomReader io . Reader ) ( [ ] image . Image , error ) { dcm , err := ioutil . ReadAll ( dicomReader ) if err != nil { return nil , err } p , err := dicom . NewParserFromBytes ( dcm , nil ) if err != nil { return nil , err } parsedData , err := bulkprocess . SafelyDicomParse ( p , dicom . ParseOptions { DropPixelData : false , } ) if parsedData == nil || err != nil { return nil , fmt . Errorf ( " " ) } var output [ ] image . Image for _ , elem := range parsedData . Elements { if elem . Tag == dicomtag . PixelData { data := elem . Value [ 0 ] . ( element . PixelDataInfo ) for _ , frame := range data . Frames { if frame . IsEncapsulated ( ) { return nil , fmt . Errorf ( " " ) } i := image . NewGray ( image . Rect ( 0 , 0 , frame . NativeData . Cols , frame . NativeData . Rows ) ) for j := 0 ; j < len ( frame . NativeData . Data ) ; j ++ { intensity := byte ( frame . NativeData . Data [ j ] [ 0 ] ) i . SetGray ( j % frame . NativeData . Cols , j / frame . NativeData . Rows , color . Gray { intensity } ) } output = append ( output , i ) } } } return output , nil }
DicomToImage constructs native go Image types from the dicom images.
DicomToImage constructs native go Image types from the dicom images .
//i := image.NewRGBA(image.Rect(0, 0, frame.NativeData.Cols, frame.NativeData.Rows)) // To the extent that I can tell, we are receiving 8-bit grayscale information. //i.SetRGBA(j%frame.NativeData.Cols, j/frame.NativeData.Rows, color.RGBA{R: intensity, B: intensity, G: intensity, A: 255})