示例#1
0
        public static MapHeader ReadFromFile(BinaryReader reader, FileInfo info, int2 headerlessSliceDims, long headerlessOffset, Type headerlessType)
        {
            MapHeader Header = null;

            if (info.Extension.ToLower() == ".mrc" || info.Extension.ToLower() == ".mrcs" || info.Extension.ToLower() == ".ali" || info.Extension.ToLower() == ".rec" || info.Extension.ToLower() == ".st")
            {
                Header = new HeaderMRC(reader);
            }
            else if (info.Extension.ToLower() == ".em")
            {
                Header = new HeaderEM(reader);
            }
            else if (info.Extension.ToLower() == ".tif" || info.Extension.ToLower() == ".tiff")
            {
                Header = new HeaderTiff(info.FullName);
            }
            else if (info.Extension.ToLower() == ".dat")
            {
                long SliceElements = headerlessSliceDims.Elements() * ImageFormatsHelper.SizeOf(headerlessType);
                long Slices        = (info.Length - headerlessOffset) / SliceElements;
                int3 Dims3         = new int3(headerlessSliceDims.X, headerlessSliceDims.Y, (int)Slices);
                Header = new HeaderRaw(Dims3, headerlessOffset, headerlessType);
            }
            else
            {
                throw new Exception("File type not supported.");
            }

            return(Header);
        }
示例#2
0
        public static MapHeader ReadFromFile(BinaryReader reader, string path, int2 headerlessSliceDims, long headerlessOffset, Type headerlessType, Stream stream = null)
        {
            MapHeader Header = null;
            string Extension = Helper.PathToExtension(path).ToLower();

            if (Extension == ".mrc" || Extension == ".mrcs" || Extension == ".rec" || Extension == ".st")
                Header = new HeaderMRC(reader);
            else if (Extension == ".em")
                Header = new HeaderEM(reader);
            else if (Extension == ".dm4" || Extension == ".dm3")
                Header = new HeaderDM4(reader);
            else if (Extension == ".tif" || Extension == ".tiff")
                Header = new HeaderTiff(path, stream);
            else if (Extension == ".eer")
                Header = new HeaderEER(path, stream);
            else if (Extension == ".dat")
            {
                FileInfo info = new FileInfo(path);

                long SliceElements = headerlessSliceDims.Elements() * ImageFormatsHelper.SizeOf(headerlessType);
                long Slices = (info.Length - headerlessOffset) / SliceElements;
                int3 Dims3 = new int3(headerlessSliceDims.X, headerlessSliceDims.Y, (int)Slices);
                Header = new HeaderRaw(Dims3, headerlessOffset, headerlessType);
            }
            else
                throw new Exception("File type not supported.");

            return Header;
        }
示例#3
0
文件: DM4.cs 项目: ssingh23-lab/warp
        public HeaderDM4(BinaryReader reader)
        {
            Reader = new BinaryReaderMixedEndian(reader);

            pixelOffset = 0;

            //LOGGER.info("Verifying Gatan format");

            littleEndian = false;
            pixelSizes   = new List <Double>();
            units        = new List <String>();

            Reader.SetEndian(littleEndian);

            // only support version 3
            version = Reader.ReadInt32();
            if (version != 3 && version != 4)
            {
                throw new FormatException("invalid header");
            }

            //LOGGER.info("Reading tags");

            Reader.ReadBytes(4);
            skipPadding(Reader);
            littleEndian = Reader.ReadInt32() != 1;
            Reader.SetEndian(littleEndian);

            // TagGroup instance

            Reader.ReadBytes(2);
            skipPadding(Reader);
            int numTags = Reader.ReadInt32();

            if (numTags > Reader.BaseStream.Length)
            {
                littleEndian = !littleEndian;
                Reader.SetEndian(littleEndian);
                adjustEndianness = false;
            }
            //LOGGER.debug("tags ({}) {", numTags);
            try
            {
                parseTags(Reader, numTags, null, "  ");
            }
            catch (Exception e)
            {
                throw new FormatException("Unable to parse metadata tag", e);
            }
            //LOGGER.debug("}");

            //LOGGER.info("Populating metadata");

            littleEndian = true;

            if (Dimensions.X == 0 || Dimensions.Y == 0)
            {
                throw new FormatException("Dimensions information not found");
            }

            if (Dimensions.Z == 0)
            {
                Dimensions.Z = 1;
            }
            //m.sizeC = 1;
            //m.sizeT = 1;
            //m.dimensionOrder = "XYZTC";
            //m.imageCount = getSizeZ() * getSizeC() * getSizeT();

            int bytes = (int)(numPixelBytes / Dimensions.Elements());

            if (bytes != ImageFormatsHelper.SizeOf(ValueType))
            {
                throw new Exception("Bytes per pixel does not match the actual size of image data.");
            }

            reader.BaseStream.Seek(pixelOffset, SeekOrigin.Begin);
        }