Skip to content

Commit

Permalink
Refactoring: extract method
Browse files Browse the repository at this point in the history
  • Loading branch information
jabriffa committed Jun 13, 2018
1 parent 1db1ffa commit ca921d4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
14 changes: 14 additions & 0 deletions pyshared/jbcr2.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,17 @@ def unslice_image(a, width, height, slices):
col_e = col_s + sw
I[:,col_s:col_e] = a.flat[col_s*height:col_e*height].reshape(height,sw)
return I

## slice sensor image

def slice_image(I, width, height, slices):
# make a list of the width of each slice
slice_widths = [slices[1]] * slices[0] + [slices[2]]
assert sum(slice_widths) == width
# slice image
a = np.zeros((height, width), dtype=np.dtype('>H'))
for i, sw in enumerate(slice_widths):
col_s = sum(slice_widths[0:i])
col_e = col_s + sw
a.flat[col_s*height:col_e*height] = I[:,col_s:col_e].flat
return a
19 changes: 7 additions & 12 deletions raw_encode.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,25 +49,20 @@ def main():

# See raw_decode.py for color components & slicing example

# obtain required parameters from RAW file
# read input raw file
tiff = jbtiff.tiff_file(open(args.raw, 'rb'))
width,height = tiff.get_sensor_size()
slices = tiff.get_slices()

# load sensor image
I = jbtiff.pnm_file.read(open(args.input,'rb'))

# obtain required parameters from RAW file
width,height = tiff.get_sensor_size()
slices = tiff.get_slices()
# check input image parameters
assert len(I.shape) == 2 # must be a one-channel image
assert I.shape == (height,width) # image size must be exact

# make a list of the width of each slice
slice_widths = [slices[1]] * slices[0] + [slices[2]]
assert sum(slice_widths) == width
# first slice image
a = np.zeros((height, width), dtype=np.dtype('>H'))
for i, sw in enumerate(slice_widths):
col_s = sum(slice_widths[0:i])
col_e = col_s + sw
a.flat[col_s*height:col_e*height] = I[:,col_s:col_e].flat
a = jbcr2.slice_image(I, width, height, slices)

# determine color components to create
components = []
Expand Down

0 comments on commit ca921d4

Please sign in to comment.