Changeset bdd71f4 in sasview
- Timestamp:
- Mar 27, 2009 1:22:51 PM (16 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- 2c0f2a5
- Parents:
- 1047275
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
DataLoader/readers/tiff_reader.py
rdaa56d0 rbdd71f4 16 16 import math, logging, os 17 17 import numpy 18 from DataLoader.data_info import Data2D18 from DataLoader.data_info import Image2D#Data2D 19 19 20 20 class Reader: … … 45 45 46 46 # Instantiate data object 47 output = Data2D()47 output = Image2D() 48 48 output.filename = os.path.basename(filename) 49 49 … … 53 53 except : 54 54 raise RuntimeError,"cannot open %s"%(filename) 55 data = im.getdata() 55 data = im.load() 56 print im.mode 57 im.show() 58 x_range = im.size[0] 59 y_range = im.size[1] 56 60 57 61 # Initiazed the output data object 58 output. data = numpy.zeros([im.size[0],im.size[1]])59 62 output.image = numpy.zeros([y_range,x_range]) 63 60 64 # Initialize 61 65 x_vals = [] 62 66 y_vals = [] 67 if im.mode == "P": 68 data=im.split() 63 69 64 70 # x and y vectors 65 for i_x in range( im.size[0]):71 for i_x in range(x_range): 66 72 x_vals.append(i_x) 67 73 68 itot = 069 for i_y in range( im.size[1]):74 75 for i_y in range(y_range): 70 76 y_vals.append(i_y) 71 72 for val in data: 73 try: 74 value = float(val) 75 except: 76 logging.error("tiff_reader: had to skip a non-float point") 77 continue 77 78 for i_x in range(x_range): 79 for i_y in range(y_range): 78 80 79 # Get bin number 80 if math.fmod(itot, im.size[0])==0: 81 i_x = 0 82 i_y += 1 83 else: 84 i_x += 1 81 try: 82 if data[i_x,i_y].__class__.__name__=="tuple": 83 84 if len(data[i_x,i_y]) == 3: 85 R,G,B= data[i_x,i_y] 86 #Converting to L Mode: uses the ITU-R 601-2 luma transform. 87 value = 255-float(R * 299/1000 + G * 587/1000 + B * 114/1000) 88 89 elif len(data[i_x,i_y]) == 4: 90 R,G,B,I = data[i_x,i_y] 91 #Take only I 92 value = 255-float(R * 299/1000 + G * 587/1000 + B * 114/1000)-float(I) 93 else: 94 #Take it as Intensity 95 #value = 255-float(data[i_x,i_y]) 96 except: 97 logging.error("tiff_reader: had to skip a non-float point") 98 continue 85 99 86 output.data[im.size[1]-1-i_y][i_x] = value 87 88 itot += 1 89 90 output.xbins = im.size[0] 91 output.ybins = im.size[1] 100 101 output.image[y_range-i_y-1,i_x] = value 102 103 output.xbins = x_range 104 output.ybins = y_range 92 105 output.x_bins = x_vals 93 106 output.y_bins = y_vals 94 107 output.xmin = 0 95 output.xmax = im.size[0]-1108 output.xmax = x_range 96 109 output.ymin = 0 97 output.ymax = im.size[0]-1110 output.ymax = y_range 98 111 99 112 return output
Note: See TracChangeset
for help on using the changeset viewer.