1
2
3import time
4import smilPython as smil
5from PIL import Image
6import numpy as np
7import pdb
8
9
10def ImageFromArray(im_arr):
12 im_np = im.getNumpyArray()
13 im_np[:] = im_arr.transpose()[:]
14 return im
15
16
17in_file = "init.png"
18Size = 20
19tolerance = 2
20step = 10
21NN = 100
22
23img = Image.open(in_file)
24XX, YY = img.size
25img_out = np.zeros((YY, XX), np.uint8)
26
27for yy in np.arange(0, YY, NN):
28 for xx in np.arange(0, XX, NN):
29 img_ii = np.array(img)[yy:min(yy + NN, YY),
30 xx:min(xx + NN, XX)].transpose()
32 im_in_np = im_in.getNumpyArray()
33 im_in_np[:] = img_ii[:]
34
36 smil.parsimoniousPathOpening(im_in, Size, tolerance, step,
37 False, im_out)
38 im_out_np = im_out.getNumpyArray().transpose()
39 img_out_slice = img_out[yy:min(yy + NN, YY), xx:min(xx + NN, XX)]
40 img_out_slice[:] = im_out_np[:]
41
42img_reconstr = ImageFromArray(img_out)
43img_out = ImageFromArray(img_out)
44im_in = ImageFromArray(np.array(img))
45
48smil.write(img_reconstr,
"init_path_open_reconstr.png")
49
Main Image class.
Definition DImage.hpp:57
RES_T geoBuild(const Image< T > &imIn, const Image< T > &imMask, Image< T > &imOut, const StrElt &se=DEFAULT_SE)
geoBuild() - Geodesic Reconstruction
Definition DMorphoGeodesic.hpp:144
RES_T write(const Image< T > &image, const char *filename)
Write image into file.
Definition DImageIO.hxx:184