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 Mars Rover (CheMin) |
---|
15 | tif files, so default parameters are for that. |
---|
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 | '''Reads standard PNG images; parameters are set to those of the |
---|
26 | Mars Rover (CheMin) diffractometer. |
---|
27 | ''' |
---|
28 | def __init__(self): |
---|
29 | super(self.__class__,self).__init__( # fancy way to self-reference |
---|
30 | extensionlist=('.png',), |
---|
31 | strictExtension=True, |
---|
32 | formatName = 'PNG image', |
---|
33 | longFormatName = 'PNG image from CheMin' |
---|
34 | ) |
---|
35 | |
---|
36 | def ContentsValidator(self, filepointer): |
---|
37 | '''no test at this time |
---|
38 | ''' |
---|
39 | return True |
---|
40 | |
---|
41 | def Reader(self,filename,filepointer, ParentFrame=None, **unused): |
---|
42 | '''Reads using standard scipy PNG reader |
---|
43 | ''' |
---|
44 | import scipy.misc |
---|
45 | self.Image = scipy.misc.imread(filename,flatten=True) |
---|
46 | self.Npix = self.Image.size |
---|
47 | if self.Npix == 0: |
---|
48 | return False |
---|
49 | if ParentFrame: |
---|
50 | self.Comments = ['no metadata'] |
---|
51 | pixy = list(self.Image.shape) |
---|
52 | sizexy = [40,40] |
---|
53 | self.Data = {'wavelength': 1.78892, 'pixelSize': sizexy, 'distance': 18.0,'size':pixy} |
---|
54 | self.Data['center'] = [pixy[0]*sizexy[0]/1000,pixy[1]*sizexy[1]/2000] |
---|
55 | G2IO.EditImageParms(ParentFrame,self.Data,self.Comments,self.Image,filename) |
---|
56 | self.LoadImage(ParentFrame,filename) |
---|
57 | return True |
---|