<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Use pretrained model
Step1:  Get the image data
Step2:  Train gaussian mixture model and save it to file
Step3:  Run segmentation faster by loading model from file
The advantage is higher with the higher number of seeds.
Step4:  The seeds does not have to be used if model is loaded from file
<ASSISTANT_TASK:>
Python Code:
from imcut import pycut
import numpy as np
import scipy.ndimage
import matplotlib.pyplot as plt
from datetime import datetime
def make_data(sz=32, offset=0, sigma=80):
    seeds = np.zeros([sz, sz, sz], dtype=np.int8)
    seeds[offset + 12, offset + 9 : offset + 14, offset + 10] = 1
    seeds[offset + 20, offset + 18 : offset + 21, offset + 12] = 1
    img = np.ones([sz, sz, sz])
    img = img - seeds
    seeds[
        offset + 3 : offset + 15, offset + 2 : offset + 6, offset + 27 : offset + 29
    ] = 2
    img = scipy.ndimage.morphology.distance_transform_edt(img)
    segm = img < 7
    img = (100 * segm + sigma * np.random.random(img.shape)).astype(np.uint8)
    return img, segm, seeds
# make_data()
Explanation: Use pretrained model
End of explanation
img, seg, seeds = make_data(64, 20)
i = 30
plt.imshow(img[i, :, :], cmap='gray')
Explanation: Get the image data
End of explanation
segparams = {
    # 'method':'graphcut',
    "method": "graphcut",
    "use_boundary_penalties": False,
    "boundary_dilatation_distance": 2,
    "boundary_penalties_weight": 1,
    "modelparams": {
        "type": "gmmsame",
        "fv_type": "intensity",
        # 'fv_extern': fv_function,
        "adaptation": "original_data",
    },
}
gc = pycut.ImageGraphCut(img, segparams=segparams)
gc.set_seeds(seeds)
t0 = datetime.now()
gc.run()
print(f"time cosumed={datetime.now()-t0}")
plt.imshow(img[i, :, :], cmap='gray')
plt.contour(gc.segmentation[i,:,:])
plt.show()
mdl_stored_file = "test_model.p"
gc.save(mdl_stored_file)
Explanation: Train gaussian mixture model and save it to file
End of explanation
# forget
gc = None
img, seg, seeds = make_data(56, 18)
gc = pycut.ImageGraphCut(img)
gc.load(mdl_stored_file)
gc.set_seeds(seeds)
t0 = datetime.now()
gc.run(run_fit_model=False)
print(f"time cosumed={datetime.now()-t0}")
plt.imshow(img[i, :, :], cmap='gray')
plt.contour(gc.segmentation[i,:,:])
plt.show()
Explanation: Run segmentation faster by loading model from file
The advantage is higher with the higher number of seeds.
End of explanation
# forget
gc = None
img, seg, seeds = make_data(56, 18)
gc = pycut.ImageGraphCut(img)
gc.load(mdl_stored_file)
t0 = datetime.now()
gc.run(run_fit_model=False)
print(f"time cosumed={datetime.now()-t0}")
plt.imshow(img[i, :, :], cmap='gray')
plt.contour(gc.segmentation[i,:,:])
plt.show()
Explanation: The seeds does not have to be used if model is loaded from file
End of explanation
<END_TASK>