适应度度量
两块拼图如果拼在一块的话 则Left-Right方向 相邻的两列色差较小。同理Top-down方向相邻两行的色差会较小1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30def dissimilarity_measure(first_piece, second_piece, orientation="LR"):
"""
依据:在所有颜色通道上的所有相邻像素上的颜色差异。
原始图像中相邻的拼图块趋于共享
类似的颜色沿其邻接边缘,即,即所有相邻像素的平方色差之和
(在所有三个颜色带上)
应该是最小的。
"""
rows, columns, _ = first_piece.shape()
color_difference = None
# | L | - | R |
if orientation == "LR":
color_difference = first_piece[:rows, columns - 1, :] - second_piece[:rows, 0, :]
# | T |
# |
# | D |
if orientation == "TD":
color_difference = first_piece[rows - 1, :columns, :] - second_piece[0, :columns, :]
squared_color_difference = np.power(color_difference / 255.0, 2)
#行相加
color_difference_per_row = np.sum(squared_color_difference, axis=1)
#列相加
total_difference = np.sum(color_difference_per_row, axis=0)
value = np.sqrt(total_difference)
return value
1 | #个体:拼图的一种解决方案 |
轮盘赌选择法
1 | #轮盘赌选择 |
参考链接
https://blog.csdn.net/zheng_zhiwei/article/details/23209729
https://www.cnblogs.com/adelaide/articles/5679475.html