()
| 78 | plt.show() |
| 79 | |
| 80 | def demo_densecrf2(): |
| 81 | I = Image.open('../dependency/densecrf/examples/im3.ppm') |
| 82 | Iq = np.asarray(I, np.uint8) |
| 83 | |
| 84 | # load initial labels, and convert it into an array 'prob' with shape [H, W, C] |
| 85 | # where C is the number of labels |
| 86 | # prob[h, w, c] means the probability of pixel at (h, w) belonging to class c. |
| 87 | L = Image.open('../dependency/densecrf/examples/anno3.ppm') |
| 88 | Lq = np.asarray(L, np.float32) |
| 89 | color_list = [[0, 128, 0], [192, 128, 0], [64, 64, 0]] |
| 90 | prob = convert_label_to_probability_map(Lq, color_list) |
| 91 | |
| 92 | w1 = 10.0 # weight of bilateral term |
| 93 | alpha = 80 # spatial std |
| 94 | beta = 13 # rgb std |
| 95 | w2 = 3.0 # weight of spatial term |
| 96 | gamma = 3 # spatial std |
| 97 | it = 5.0 # iteration |
| 98 | param = (w1, alpha, beta, w2, gamma, it) |
| 99 | lab = densecrf(Iq, prob, param) |
| 100 | lab = colorize_label_map(lab, color_list) |
| 101 | lab = Image.fromarray(lab) |
| 102 | plt.subplot(1,3,1); plt.axis('off'); plt.imshow(I); plt.title('input image') |
| 103 | plt.subplot(1,3,2); plt.axis('off'); plt.imshow(L); plt.title('initial label') |
| 104 | plt.subplot(1,3,3); plt.axis('off'); plt.imshow(lab); plt.title('after dense CRF') |
| 105 | plt.show() |
| 106 | |
| 107 | if __name__ == "__main__": |
| 108 | print("example list") |
no test coverage detected