1 | # -*- coding: utf-8 -*- |
---|
2 | ########### SVN repository information ################### |
---|
3 | # $Date: 2014-12-27 11:14:59 -0600 (Sat, 27 Dec 2014) $ |
---|
4 | # $Author: $ |
---|
5 | # $Revision: $ |
---|
6 | # $URL: $ |
---|
7 | # $Id: $ |
---|
8 | ########### SVN repository information ################### |
---|
9 | ''' |
---|
10 | *Module G2img_png: png image file* |
---|
11 | --------------------------------------- |
---|
12 | |
---|
13 | Routine to read an image in .png (Portable Network Graphics) format. |
---|
14 | For now, the only known use of this is with converted CheMin tif files |
---|
15 | so default parameters are that machine. |
---|
16 | |
---|
17 | ''' |
---|
18 | |
---|
19 | import sys |
---|
20 | import os |
---|
21 | import GSASIIIO as G2IO |
---|
22 | import GSASIIpath |
---|
23 | GSASIIpath.SetVersionNumber("$Revision: $") |
---|
24 | class png_ReaderClass(G2IO.ImportImage): |
---|
25 | def __init__(self): |
---|
26 | super(self.__class__,self).__init__( # fancy way to self-reference |
---|
27 | extensionlist=('.png',), |
---|
28 | strictExtension=True, |
---|
29 | formatName = 'PNG image', |
---|
30 | longFormatName = 'PNG image from CheMin' |
---|
31 | ) |
---|
32 | |
---|
33 | def ContentsValidator(self, filepointer): |
---|
34 | '''no test at this time |
---|
35 | ''' |
---|
36 | return True |
---|
37 | |
---|
38 | def Reader(self,filename,filepointer, ParentFrame=None, **unused): |
---|
39 | '''Read using scipy PNG reader |
---|
40 | ''' |
---|
41 | import scipy.misc |
---|
42 | self.Image = scipy.misc.imread(filename,flatten=True) |
---|
43 | self.Npix = self.Image.size |
---|
44 | if self.Npix == 0: |
---|
45 | return False |
---|
46 | if ParentFrame: |
---|
47 | self.Comments = ['no metadata'] |
---|
48 | pixy = list(self.Image.shape) |
---|
49 | sizexy = [40,40] |
---|
50 | self.Data = {'wavelength': 1.78892, 'pixelSize': sizexy, 'distance': 18.0,'size':pixy} |
---|
51 | self.Data['center'] = [pixy[0]*sizexy[0]/1000,pixy[1]*sizexy[1]/2000] |
---|
52 | G2IO.EditImageParms(ParentFrame,self.Data,self.Comments,self.Image,filename) |
---|
53 | self.LoadImage(ParentFrame,filename) |
---|
54 | return True |
---|
55 | # N.B. This replaces G2IO.GetPNGData |
---|