def to_dcm
      # Use the original DICOM object as a starting point (keeping all non-sequence elements):
      # Note: Something like dcm.dup doesn't work here because that only performs a shallow copy on the DObject instance.
      dcm = DICOM::DObject.new
      @image.dcm.each_element do |element|
        # A bit of a hack to regenerate the DICOM elements:
        begin
          if element.value
            # ATM this fails for tags with integer values converted to a backslash-separated string:
            DICOM::Element.new(element.tag, element.value, :parent => dcm)
          else
            # Transfer the binary content as long as it is not the pixel data string:
            DICOM::Element.new(element.tag, element.bin, :encoded => true, :parent => dcm)
          end
        rescue
          DICOM::Element.new(element.tag, element.value.split("\\").collect {|val| val.to_i}, :parent => dcm) if element.value
        end
      end
      dcm.delete_group('0002')
      # Format the DICOM image ensure good contrast amongst the binary pixel values:
      # Window Center:
      DICOM::Element.new('0028,1050', '128', :parent => dcm)
      # Window Width:
      DICOM::Element.new('0028,1051', '256', :parent => dcm)
      # Rescale Intercept:
      DICOM::Element.new('0028,1052', '0', :parent => dcm)
      # Rescale Slope:
      DICOM::Element.new('0028,1053', '1', :parent => dcm)
      # Pixel data:
      dcm.pixels = @narray*255
      return dcm
    end
def to_dcm
      # Use the original DICOM object as a starting point (keeping all non-sequence elements):
      # Note: Something like dcm.dup doesn't work here because that only performs a shallow copy on the DObject instance.
      dcm = DICOM::DObject.new
      @image.dcm.each_element do |element|
        # A bit of a hack to regenerate the DICOM elements:
        begin
          if element.value
            # ATM this fails for tags with integer values converted to a backslash-separated string:
            DICOM::Element.new(element.tag, element.value, :parent => dcm)
          else
            # Transfer the binary content as long as it is not the pixel data string:
            DICOM::Element.new(element.tag, element.bin, :encoded => true, :parent => dcm)
          end
        rescue
          DICOM::Element.new(element.tag, element.value.split("\\").collect {|val| val.to_i}, :parent => dcm) if element.value
        end
      end
      dcm.delete_group('0002')
      # Format the DICOM image ensure good contrast amongst the binary pixel values:
      # Window Center:
      DICOM::Element.new('0028,1050', '128', :parent => dcm)
      # Window Width:
      DICOM::Element.new('0028,1051', '256', :parent => dcm)
      # Rescale Intercept:
      DICOM::Element.new('0028,1052', '0', :parent => dcm)
      # Rescale Slope:
      DICOM::Element.new('0028,1053', '1', :parent => dcm)
      # Pixel data:
      dcm.pixels = @narray*255
      return dcm
    end
Creates a DICOM object from the BinImage instance. This is achieved by
 copying the elements of the DICOM object of the Image instance
 referenced by this BinImage, and replacing its pixel data with the
 NArray of this instance.

 @return [DICOM::DObject] the created DICOM object