數(shù)字圖像處理的期末大作業(yè)
成績(jī)出來(lái)了,感覺(jué)一般般,做個(gè)記錄
代碼圖片文件:數(shù)學(xué)建模2013年國(guó)賽B題碎紙片復(fù)原(縱切和橫縱切兩問(wèn))-統(tǒng)計(jì)分析文檔類資源-CSDN下載
目錄
第一問(wèn) 碎紙片拼接--縱切
以下為python代碼:
結(jié)果
問(wèn)題二: 碎紙片拼接--縱切+橫切
python代碼如下:
結(jié)果:
第一問(wèn) 碎紙片拼接--縱切
- 設(shè)計(jì)思路
通過(guò)二值化,將圖片灰度轉(zhuǎn)變?yōu)?-1之間(以便提高運(yùn)算速率)。在此問(wèn)題中題目給出了縱狀的切割圖片,主要的解題思路是通過(guò)計(jì)算每張圖片與左邊界的距離得到第一列圖片的序號(hào),然后遍歷第一列的圖片,為其匹配該行的圖片,最終得到縱向圖片拼接的序號(hào)。
- 算法步驟
- 對(duì)圖像進(jìn)行二值化的預(yù)處理
- 首先,求出第一列的序號(hào)(通過(guò)比較每張圖片與最左邊的距離,求出第一列的序號(hào),因?yàn)閳D片一般存在頁(yè)邊距,而第一列的圖片與左邊界的距離是相同的,都為頁(yè)邊距)
- 對(duì)于求出的第一列的圖片序號(hào),求與其邊緣匹配指數(shù)最高的圖片,即為下一圖片序號(hào),通過(guò)計(jì)算下一圖片的與其邊緣匹配指數(shù)最高的圖片為其下一圖片序號(hào)。依次遍歷得到最終的圖片拼接排序。其中,邊緣匹配指數(shù)為左邊圖片的最右邊一列像素和右邊匹配圖片的最左邊一列像素相等的個(gè)數(shù)。
以下為python代碼:
import cv2
import numpy as np
import matplotlib.pyplot as plt
import skimage.io as io
from collections import Counter
from PIL import Image
data_dir = './附件1'
path = data_dir +'/*.bmp'
coll = io.ImageCollection(path)#讀入灰度圖像
img_num = len(coll)
#*********轉(zhuǎn)矩陣*******
img = np.asarray(coll)
for i in range(0,len(coll)):
img[i] = cv2.adaptiveThreshold(src=img[i], # 要進(jìn)行處理的圖片
maxValue=1, # 大于閾值后設(shè)定的值
adaptiveMethod=cv2.ADAPTIVE_THRESH_MEAN_C, # 自適應(yīng)方法,ADAPTIVE_THRESH_MEAN_C:表區(qū)域內(nèi)均值;ADAPTIVE_THRESH_GAUSSIAN_C:表區(qū)域內(nèi)像素點(diǎn)加權(quán)求和
thresholdType=cv2.THRESH_BINARY, # 同全局閾值法中的參數(shù)一樣
blockSize=11, # 方陣(區(qū)域)大小,
C=1) # 常數(shù)項(xiàng),每個(gè)區(qū)域計(jì)算出的閾值的基礎(chǔ)上在減去這個(gè)常數(shù)作為這個(gè)區(qū)域的最終閾值,可以為負(fù)數(shù)
coll[0].shape
#計(jì)算與左邊距離 選出第一張圖片
Max = -1
index = 0
for i in range(0,img.shape[0]):
#計(jì)算
count = 0
for y in range(0,img.shape[2]):#圖片按列便利
panduan = 1
for x in range(0,img.shape[1]):
if(img[i][x][y]==0):
panduan = 0
break
if(panduan==1):
count = count+1
else:
break
if(count>Max):
Max = count
index = i
#計(jì)算每一張的右邊邊緣 檢測(cè)最匹配的圖片
ans_index = [] #用于記錄最終的排序
ans_index.append(index) #插入第一張圖片的索引
#計(jì)算每一張的邊緣 左和右 相匹配的值
while(1):
Max = -1
index = 0
zj = ans_index[len(ans_index)-1]
print(ans_index)
for i in range(0,len(coll)):
if(ans_index.count(i)==1):
continue
count = 0
for x in range(0,img.shape[1]):#遍歷行遍歷 左右元素
if(img[i][x][0]==img[zj][x][img.shape[2]-1]):
count = count + 1
if(count>Max):
Max = count
index = i
ans_index.append(index)
print(ans_index)
if(len(ans_index)==len(coll)):
break
ans_img = coll[ans_index[0]]
for i in range(0,len(ans_index)):
if(i==0):
continue
ans_img = np.hstack((ans_img, coll[ans_index[i]])) # 水平合并
ans_img.shape
im = Image.fromarray(ans_img) # to Image
im.save('result1.png')
代碼運(yùn)行結(jié)果:
結(jié)果
通過(guò)上述算法計(jì)算得到附件1的圖片拼接順序如下:
[8, 14, 12, 15, 3, 10, 2, 16, 1, 4, 5, 9, 13, 18, 11, 7, 17, 0, 6]
最終拼接得到的圖片如下所示(result1.png文件):
通過(guò)上述算法計(jì)算得到附件2的圖片拼接順序如下:
?[3, 6, 2, 7, 15, 18, 11, 0, 5, 1, 9, 13, 10, 8, 12, 14, 17, 16, 4]
最終拼接得到的圖片如下所示(result2.png文件):
問(wèn)題二: 碎紙片拼接--縱切+橫切
- 設(shè)計(jì)思路
相較于第一問(wèn),第二問(wèn)的碎片加入了縱向的切割,且通過(guò)觀察樣本,可以得知有些圖片存在空白行邊緣,行與行之間有固定的間隔。本文先對(duì)圖片中字的位置做特征提取,運(yùn)用K-meanes聚類算法分出11類。得到每行的分類,對(duì)行內(nèi)類元素進(jìn)行相似度匹配排序。將行內(nèi)排序好了的11行圖片依據(jù)圖片邊緣相似度和行間距匹配度進(jìn)行豎直方向的拼接。
- 算法步驟
- 對(duì)圖像進(jìn)行二值化處理
- 計(jì)算圖片的行列數(shù),求第一行、最后一行、第一列、最后一列的圖像序號(hào)
通過(guò)對(duì)附件3所有圖片計(jì)算圖片與左邊界的距離,得到11張距離相同、最大的圖片作為第一列,同樣計(jì)算圖片與右邊界的距離得到11張最后一列的圖片序列。
其中,第一行和最后一行的計(jì)算可以在行聚類之后計(jì)算每行與底部的空白距離,也可以在此步驟進(jìn)行計(jì)算,本文選擇在聚類之后進(jìn)行計(jì)算第一行和最后一行圖片的序號(hào)。
? ? ? ? 3、對(duì)圖像做掩碼處理
圖片存在首行縮進(jìn)、段尾,會(huì)對(duì)行間的聚類有較大的影響,所以對(duì)這類圖片進(jìn)行掩碼處理。首先計(jì)算統(tǒng)計(jì)出所有圖片的空白行高度和字體高度,通過(guò)統(tǒng)計(jì)得到字寬和行寬,通過(guò)得到的字寬和行寬對(duì)以下三種圖像進(jìn)行掩碼處理。如下為三種行空白掩碼處理的結(jié)果:
?? ??
? ??
???????????
????????4、特征提取
選擇圖片字像素所在的行數(shù)作為特征進(jìn)行提取,如下圖所示的紅線即為該圖片特征提取行數(shù)的示例圖:
對(duì)于中文和英文碎片來(lái)說(shuō),其行間特征有不同,具體如圖所示:
????????4、聚類
運(yùn)用K-means算法進(jìn)行聚類,可以得到11類行間類圖片。
????????5、根據(jù)左右相似度進(jìn)行行內(nèi)排序,通過(guò)比較行間上下邊緣相似度和上下行間距進(jìn)行豎直方向的行間拼接。
其中相似度函數(shù)通過(guò)兩個(gè)因素進(jìn)行判斷,一個(gè)是一行中歸一化后灰度值為0的個(gè)數(shù),一個(gè)是兩行中像素相等的值,通過(guò)調(diào)整loss函數(shù)中兩個(gè)因素的系數(shù),計(jì)算相似度的值。
對(duì)于中文來(lái)說(shuō),特征提取可以直接統(tǒng)計(jì)該行灰度值是否等于列數(shù),用于區(qū)分該位置(行)為空白行部分或文字部分;而對(duì)于英文的特征提取則需要用到灰度變化的斜率,當(dāng)斜率大于一定值為空白行和字的交界處,從而用于判斷提取空白行、文字位置特征。
python代碼如下:
import cv2
import numpy as np
import matplotlib.pyplot as plt
import skimage.io as io
from collections import Counter
from PIL import Image
import pandas as pd
from sklearn.cluster import KMeans#導(dǎo)入聚類模型
data_dir = './附件3'
path = data_dir +'/*.bmp'
coll = io.ImageCollection(path)#讀入灰度圖像
img_num = len(coll)
#*********轉(zhuǎn)矩陣*******
img = np.asarray(coll)
for i in range(0,len(coll)):
img[i] = cv2.adaptiveThreshold(src=img[i], # 要進(jìn)行處理的圖片
maxValue=1, # 大于閾值后設(shè)定的值
adaptiveMethod=cv2.ADAPTIVE_THRESH_MEAN_C, # 自適應(yīng)方法,ADAPTIVE_THRESH_MEAN_C:表區(qū)域內(nèi)均值;ADAPTIVE_THRESH_GAUSSIAN_C:表區(qū)域內(nèi)像素點(diǎn)加權(quán)求和
thresholdType=cv2.THRESH_BINARY, # 同全局閾值法中的參數(shù)一樣
blockSize=11, # 方陣(區(qū)域)大小,
C=1) # 常數(shù)項(xiàng),每個(gè)區(qū)域計(jì)算出的閾值的基礎(chǔ)上在減去這個(gè)常數(shù)作為這個(gè)區(qū)域的最終閾值,可以為負(fù)數(shù)
print(img.shape)
#*******計(jì)算每張圖片的左右邊距*****
left = []
right = []
for i in range(0,img.shape[0]):
#計(jì)算每張圖片同左邊的距離
count = 0
for y in range(0,img.shape[2]):#列
panduan = 1
for x in range(0,img.shape[1]):#行
if(img[i][x][y]==0):
panduan = 0
break
if(panduan==1):
count = count+1
else:
break
left.append(count)
#計(jì)算每張圖片同右邊的距離
count = 0
for y in range(img.shape[2]-1, -1, -1):#列
panduan = 1
for x in range(0,img.shape[1]):#行
if(img[i][x][y]==0):
panduan = 0
break
if(panduan==1):
count = count+1
else:
break
right.append(count)
plt.scatter(range(0,len(left)),left)
plt.scatter(range(0,len(right)),right)
print(Counter(left))
print(Counter(right))
#*****確定行數(shù)********
#可以從圖中找到11個(gè)最右邊和最左邊的圖片
#剩余的點(diǎn) 中可以計(jì)算 行間距
#從散點(diǎn)圖可以看出 行數(shù)為11
#列數(shù)為 209/11 = 19 209為img.shape[0]
fenge = 10 #看圖確定 或 通過(guò)計(jì)算得出count的平均值
col = 19 #列數(shù)
row = 11 #行數(shù) left 或 right 中count值大于 fenge的個(gè)數(shù)
#**********最后一列圖片***********
end_index = []
for i in range(0,len(right)):
if(right[i]>=fenge):
end_index.append(i)
len(end_index)
#**********找出第一列的圖片index*******
first_index = []
for i in range(0,len(left)):
if(left[i]>=fenge):
first_index.append(i)
len(first_index)
kong_width = []
zi_width = []
#********計(jì)算每張圖片連續(xù)的1和0的長(zhǎng)度********
for i in range(0,img.shape[0]):
width = 0
zj_kong = []
zj_zi = []
if(sum(img[i][0])==img.shape[2]):#空白行
qian = 0
else:
qian = 1
for x in range(0,img.shape[1]):
if(sum(img[i][x])!=img.shape[2]):#字
xian = 0
else:
xian = 1
if(qian!=xian):
if(qian == 0):
if(width):
zj_zi.append(width)
else:
if(width):
zj_kong.append(width)
width = 0
else:
width = width + 1
qian = xian
if(qian==0):#最后一行處理
zj_zi.append(width)
else:
zj_kong.append(width)
kong_width.append(zj_kong)
zi_width.append(zj_zi)
print(kong_width[0])
print(zi_width[0])
#統(tǒng)計(jì)分析
#得出字寬為40、39、38 空白行寬度為27、26、28
ans = []
for i in kong_width:
for j in i:
ans.append(j)
plt.scatter(range(0,len(ans)),ans)
print("空白行寬度統(tǒng)計(jì):"+str(Counter(ans)))
ans = []
for i in zi_width:
for j in i:
ans.append(j)
plt.scatter(range(0,len(ans)),ans)
print("字寬統(tǒng)計(jì):"+str(Counter(ans)))
img1 = img
#掩碼補(bǔ)全 對(duì)于段首空行和段尾空行處理 為聚類做預(yù)處理
chuli_index_1 = []#需處理的圖片 index 分為兩種情況 如果需處理的行在第一行 需找到下界字的邊緣行數(shù)
chuli_index_2 = []#如果不在第一行 需找到上界字的邊緣行數(shù)
count = 0
for i in kong_width:
index = 0
for j in i:
if(j>40):
if(index==0):
chuli_index_1.append(count)
else:
chuli_index_2.append(count)
break
index = index + 1
count = count + 1
print("進(jìn)行掩碼處理的圖片數(shù)量:"+str(len(chuli_index_1)+len(chuli_index_2)))
print("第一類需掩碼處理的圖片數(shù)量"+str(len(chuli_index_1)))
print("第二類需掩碼處理的圖片數(shù)量"+str(len(chuli_index_2)))
#處理
#第一種情況 需找到下界字的邊緣行數(shù)
for index in chuli_index_1:
#找到第一行
first_index_ = 0
for x in range(0,img.shape[1]):#行
if(sum(img[index][x])!=img.shape[2]):
break
first_index_ = x
if(x-27-40<0):
first = 0
else:
first = int(x-27-40)
for x in range(first,x-27):
for y in range(0,img.shape[2]):
img1[index][x][y] = 0
#第二種情況 需找到上界字的邊緣行數(shù)
for index in chuli_index_2:
#找到上界行數(shù)
width = 0
zj_kong = []
hang = []
zj_zi = []
if(sum(img[index][0])==img.shape[2]):#空白行
qian = 0
else:
qian = 1
for x in range(0,img.shape[1]):
if(sum(img[index][x])!=img.shape[2]):#字
xian = 0
else:
xian = 1
if(qian!=xian):
if(qian == 0):
if(width):
zj_zi.append(width)
else:
if(width):
zj_kong.append(width)
hang.append(x)
width = 0
else:
width = width + 1
qian = xian
if(qian==0):#最后一行處理
zj_zi.append(width)
else:
zj_kong.append(width)
hang.append(x)
Max = 0
for i in range(0,len(zj_kong)):
if(zj_kong[i]>Max):
Max = zj_kong[i]
first_index_ = hang[i]-zj_kong[i]
if(first_index_+27+40>=img.shape[1]):
end = img.shape[1]
else:
end = first_index_ + 27 + 40
for x in range(first_index_+27,end):
for y in range(0,img.shape[2]):
img1[index][x][y] = 0
#***********聚類***********
#提取特征
tezhe = []
for i in range(0,img.shape[0]):
width = 0
zj = []
if(sum(img1[i][0])==img.shape[2]):#空白行
qian = 0
else:
qian = 1
for x in range(0,img.shape[1]):
if(sum(img1[i][x])!=img.shape[2]):#字
xian = 0
else:
xian = 1
if(qian!=xian):
if(width>10):#防止出現(xiàn) 文字中間有間隔部分的情況
zj.append(x)
width = 0
else:
width = width + 1
qian = xian
tezhe.append(zj)
ans = []
for i in range(0,len(tezhe)):
zj = []
zj.append(tezhe[i][0])
zj.append(tezhe[i][1])
# zj.append(tezhe[i][2])
# zj.append(tezhe[i][3])
ans.append(zj)
x_train = pd.DataFrame(ans)
kmeansmodel = KMeans(n_clusters=11, init='k-means++')
y_kmeans = kmeansmodel.fit_predict(x_train)
print("聚類結(jié)果統(tǒng)計(jì):"+str(Counter(y_kmeans)))
#分類結(jié)果
ans = {}
count = 0
for i in y_kmeans:
if(i in ans.keys()):
ans[i].append(count)
else:
zj = []
zj.append(count)
ans[i] = zj
count += 1
ans_lei = ans
#*******行內(nèi)排序******
img1 = img
img = np.asarray(coll)
for i in range(0,len(coll)):
img[i] = cv2.adaptiveThreshold(src=img[i], # 要進(jìn)行處理的圖片
maxValue=1, # 大于閾值后設(shè)定的值
adaptiveMethod=cv2.ADAPTIVE_THRESH_MEAN_C, # 自適應(yīng)方法,ADAPTIVE_THRESH_MEAN_C:表區(qū)域內(nèi)均值;ADAPTIVE_THRESH_GAUSSIAN_C:表區(qū)域內(nèi)像素點(diǎn)加權(quán)求和
thresholdType=cv2.THRESH_BINARY, # 同全局閾值法中的參數(shù)一樣
blockSize=11, # 方陣(區(qū)域)大小,
C=1) # 常數(shù)項(xiàng),每個(gè)區(qū)域計(jì)算出的閾值的基礎(chǔ)上在減去這個(gè)常數(shù)作為這個(gè)區(qū)域的最終閾值,可以為負(fù)數(shù)
hang_index = []
for i in range(0,len(ans_lei)):
ans_index = [] #用于記錄的排序
ans_index.append(first_index[i]) #插入第一張圖片的索引
count1 = 0
while(count1<len(ans_lei[y_kmeans[first_index[i]]])-2):
count1 = count1 + 1
Max = -1
index = 0
zj = ans_index[len(ans_index)-1]
for j in ans_lei[y_kmeans[first_index[i]]]:
if(ans_index.count(j)==1 or end_index.count(j)==1):
if(end_index.count(j)==1):
yc = j
continue
count = 0
for x in range(0,img.shape[1]):#遍歷行遍歷 左右元素
if(img[j][x][0]==img[zj][x][img.shape[2]-1] ):
if(img[j][x][0]==0):
count +=0.6
count = count + 1
count2 = abs(sum(img[j][0])-sum(img[zj][img.shape[1]-1]))
loss = count*0.5 -count1*0.8
if(loss>Max):
Max = loss
index = j
ans_index.append(index)
ans_index.append(yc)
print(ans_index)
hang_index.append(ans_index)
#******按行拼接圖片查看效果********排序效果很好
ans_hang_img = []
for i in range(0,len(hang_index)):
ans_img = coll[hang_index[i][0]]
for j in range(0,len(hang_index[i])):
if(j==0):
continue
ans_img = np.hstack((ans_img, coll[hang_index[i][j]])) # 水平合并
ans_hang_img.append(ans_img)
im = Image.fromarray(ans_hang_img[5]) # to Image
img_ = np.array(ans_hang_img)
img_.shape#11行圖片
#二值化 加快運(yùn)算速度
for i in range(0,len(img_)):
img_[i] = cv2.adaptiveThreshold(src=img_[i], # 要進(jìn)行處理的圖片
maxValue=1, # 大于閾值后設(shè)定的值
adaptiveMethod=cv2.ADAPTIVE_THRESH_MEAN_C, # 自適應(yīng)方法,ADAPTIVE_THRESH_MEAN_C:表區(qū)域內(nèi)均值;ADAPTIVE_THRESH_GAUSSIAN_C:表區(qū)域內(nèi)像素點(diǎn)加權(quán)求和
thresholdType=cv2.THRESH_BINARY, # 同全局閾值法中的參數(shù)一樣
blockSize=11, # 方陣(區(qū)域)大小,
C=1) # 常數(shù)項(xiàng),每個(gè)區(qū)域計(jì)算出的閾值的基礎(chǔ)上在減去這個(gè)常數(shù)作為這個(gè)區(qū)域的最終閾值,可以為負(fù)數(shù)
#*******將以上拼接好的行圖片進(jìn)行豎方向的拼接
#***找到第一行index
Max = 0
first_hang_index = 0
for i in range(0,img_.shape[0]):
#計(jì)算每張行圖片同頂部的距離
for x in range(0,img_.shape[1]):#行
if(sum(img_[i][x])!=img_.shape[2]):
if(x>Max):
Max = x
first_hang_index = i
break
#***找到最后一行index
Max = 0
end_hang_index = 0
for i in range(0,img_.shape[0]):
#計(jì)算每張行圖片同頂部的距離
for x in range(img_.shape[1]-1,-1,-1):#行
if(sum(img_[i][x])!=img_.shape[2]):
if(179-x>Max):
Max =179- x
end_hang_index = i
break
#列排序
lie_index = []
lie_index.append(first_hang_index)#行排序 列的第一個(gè) 行圖片index
while(1):
Max = -1
index = 0
zj = lie_index[len(lie_index)-1]
for j in range(0,img_.shape[0]):
if(lie_index.count(j)==1 or j == end_hang_index):
continue
count = 0
for y in range(0,img_.shape[2]):#遍歷行遍歷
if(img_[j][0][y]==img_[zj][img_.shape[1]-1][y] ):
if(img_[j][0][y]==0):
count +=0.3
count = count + 1
count1 = abs(sum(img_[j][0])-sum(img_[zj][img_.shape[1]-1]))
loss = count*0.5 -count1*0.3
if(loss>Max):
Max = loss
index = j
lie_index.append(index)
if(len(lie_index)>=img_.shape[0]-1):
break
lie_index.append(end_hang_index)
print("列排序:"+str(lie_index))
#******圖片列拼接 輸出最終拼接圖片 基于拼接好的ans_hang_img圖片矩陣
ans_img = []
ans_img = ans_hang_img[lie_index[0]]
for i in range(0,len(lie_index)):
if(i==0):
continue
ans_img = np.vstack((ans_img, ans_hang_img[lie_index[i]])) #
im = Image.fromarray(ans_img) # to Image
im.save('result3.png')
結(jié)果:
- 字寬和行寬
以下為中文字寬和行寬的個(gè)數(shù)統(tǒng)計(jì),可以看出空白行寬的大小應(yīng)為27、26、28;字寬的大小應(yīng)為40、39、38。
空白行寬度統(tǒng)計(jì):Counter({27: 177, 26: 80, 28: 74,?29: 28, 21: 15, 24: 14, 18: 14, 30: 13, 58: 13, 8: 13, 2: 10, 15: 10, 14: 9, 95: 9, 5: 9, 12: 8, 7: 8, 37: 8, 1: 7, 6: 7, 20: 6, 36: 5, 70: 5, 57: 5, 31: 4, 25: 4, 96: 4, 38: 3, 82: 3, 13: 3, 3: 3, 83: 3, 9: 3, 94: 2, 99: 2, 39: 2, 97: 2, 92: 1, 4: 1, 23: 1, 56: 1, 17: 1, 98: 1, 68: 1, 19: 1, 59: 1, 40: 1, 44: 1, 93: 1, 16: 1, 64: 1, 71: 1, 55: 1, 84: 1})
字寬統(tǒng)計(jì):Counter({40: 137, 39: 134, 38: 61, 37: 33, 36: 19, 21: 17, 27: 16, 3: 15, 15: 15, 5: 14, 11: 14, 17: 14, 34: 13, 33: 12, 24: 11, 18: 10, 4: 10, 41: 9, 35: 8, 23: 5, 14: 4, 0: 4, 19: 4, 16: 3, 12: 3, 20: 3, 10: 3, 26: 2, 25: 2, 22: 2, 9: 2, 2: 1, 8: 1, 28: 1, 6: 1, 32: 1})
以下為英文字寬和行寬的個(gè)數(shù)統(tǒng)計(jì),可以看出空白行寬的大小應(yīng)為25;字寬的大小應(yīng)為36、24、37。
空白行寬度統(tǒng)計(jì):Counter({25: 93, 26: 61, 38: 59, 24: 50, 37: 43, 17: 34, 4: 32, 27: 28, 7: 26, 8: 24, 30: 18, 11: 17, 18: 16, 29: 15, 12: 14, 3: 12, 31: 11, 19: 10, 14: 10, 9: 9, 47: 8, 13: 8, 28: 8, 60: 6, 10: 6, 90: 5, 20: 5, 51: 5, 61: 5, 6: 5, 40: 5, 36: 4, 103: 4, 49: 4, 91: 3, 2: 3, 39: 3, 5: 3, 64: 3, 16: 3, 15: 2, 50: 2, 23: 2, 52: 2, 114: 1, 105: 1, 101: 1, 48: 1, 56: 1, 89: 1, 32: 1, 33: 1, 92: 1, 102: 1, 86: 1, 104: 1})
字寬統(tǒng)計(jì):Counter({36: 98, 24: 96, 37: 89,?35: 46, 23: 38, 34: 37, 1: 31, 5: 28, 31: 25, 2: 23, 50: 21, 22: 19, 0: 17, 32: 13, 13: 13, 21: 11, 14: 9, 49: 8, 4: 8, 9: 7, 3: 5, 30: 5, 33: 5, 27: 4, 45: 4, 12: 3, 48: 3, 20: 3, 11: 2, 7: 2, 6: 2, 41: 1, 47: 1, 40: 1, 17: 1, 28: 1, 8: 1, 43: 1, 15: 1, 42: 1})
- K-mewns聚類結(jié)果:
如下為聚類類別統(tǒng)計(jì):
如下為每張圖片所屬的類別序號(hào):
[ 4, ?3, ?2, ?5, ?6, ?9, ?1, ?4, ?0, ?0, ?9, ?2, ?5, ?8, ?5, ?7, ?8,
????????7, ?3, ?1, ?1, ?8, ?2, ?3, ?0, ?0, ?3, ?7, ?2, ?9, ?3, ?5, ?4, ?7,
???????10, ?0, ?1, ?9, ?0, ?5, ?6, ?3, 10, 10, ?9, ?4, ?0, 10, ?9, ?2, ?3,
????????5, ?1, ?4, ?2, ?9, ?4, ?2, 10, ?9, ?7, ?1, ?3, ?1, ?9, ?2, ?8, ?1,
????????4, ?1, ?4, ?7, ?1, ?5, ?0, ?9, ?3, 10, ?1, ?1, ?7, ?0, ?5, ?7, 10,
????????7, ?3, ?3, ?0, ?6, 10, ?2, ?9, ?4, 10, ?2, ?1, 10, ?9, ?1, ?3, ?6,
????????6, ?0, ?9, ?0, ?8, ?5, ?6, ?8, ?8, ?9, 10, ?6, ?6, ?5, ?1, ?6, ?2,
????????6, ?3, 10, ?0, ?6, 10, ?8, ?4, 10, ?5, ?2, ?0, ?1, ?7, ?7, ?5, ?5,
???????10, ?4, ?4, ?8, ?6, ?2, ?3, ?2, 10, ?8, ?6, ?3, ?0, 10, ?8, ?6, ?7,
????????4, ?6, ?6, ?7, ?8, ?4, ?5, ?5, ?0, ?1, ?1, 10, ?7, ?4, ?0, ?3, ?5,
????????7, ?9, ?9, ?8, ?4, ?4, ?5, ?1, ?2, ?3, ?9, ?8, ?8, 10, ?8, ?6, ?2,
????????8, ?2, ?0, ?2, ?3, ?2, ?0, ?6, ?3, ?4, ?8, ?7, ?5, ?7, ?9, ?7, ?5,
????????8, ?7, ?9, ?6, ?4]
- 行列排列順序
行內(nèi)排序:
[7, 208, 138, 158, 126, 68, 175, 45, 174, 0, 137, 53, 56, 93, 153, 70, 166, 32, 196]
[14, 128, 3, 159, 82, 199, 135, 12, 73, 160, 203, 169, 134, 39, 31, 51, 107, 115, 176]
[29, 64, 111, 201, 5, 92, 180, 48, 37, 75, 55, 44, 206, 10, 104, 98, 172, 171, 59]
[38, 24, 35, 81, 189, 122, 103, 130, 193, 88, 167, 25, 8, 105, 161, 9, 46, 148, 74]
[49, 54, 65, 143, 186, 2, 57, 192, 178, 118, 190, 95, 11, 22, 129, 28, 91, 188, 141]
[61, 19, 78, 67, 69, 99, 162, 96, 131, 79, 63, 116, 163, 72, 6, 177, 20, 52, 36]
[71, 156, 80, 33, 202, 198, 15, 133, 170, 205, 85, 152, 165, 27, 83, 132, 200, 17, 60]
[89, 146, 4, 101, 113, 194, 119, 114, 40, 151, 207, 155, 140, 185, 108, 117, 102, 154, 123]
[94, 34, 84, 183, 90, 47, 121, 42, 124, 144, 77, 112, 149, 97, 136, 164, 127, 58, 43]
[125, 13, 182, 109, 197, 16, 184, 110, 187, 66, 106, 150, 21, 173, 157, 181, 204, 139, 145]
[168, 100, 76, 62, 142, 30, 41, 23, 147, 191, 50, 179, 120, 86, 195, 26, 1, 87, 18]
列排序:
[4, 5, 1, 8, 9, 2, 0, 10, 3, 6, 7]
- 圖片復(fù)原結(jié)果
如下圖所示(result3.png文件)文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-526462.html
文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-526462.html
到了這里,關(guān)于(數(shù)學(xué)建模)2013年國(guó)賽B題-碎紙片復(fù)原python代碼的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!