最近在做把matlab代碼轉成python代碼,沒有用過matlab,python也只是局限於爬蟲,所以....
matlab與python最大的不同是,matlab的下標是從1開始的,python和C語言C++都是下標從0開始的,在matlab中,對圖片縮放,有一個imresize函數,Resize the image, specifying scale factor and using default interpolation method and antialiasing.在Python在,有resize函數,但是對圖片的縮放效果不同。
matlab中的kmean
[cluster_idx cluster_center] = kmeans(ab,nColors,'distance','sqEuclidean','Replicates',1,'EmptyAction','drop', 'Options',opts);
在Python中:
nColors = 5 cluster_idx = KMeans(n_clusters=nColors, max_iter=38,n_init=40, init='k-means++',n_jobs=-1).fit(ab) cluster__center = cluster_idx.cluster_centers_
在matlab中有有從rgb轉化成lab的圖片
if length(size(I)) >2 I=rgb2gray(I);
在python中當圖片的維度大於2時,進行轉換,並且在轉換前,都要將矩陣里面的值轉換成int類型。
image_orig = image_orig.astype(np.uint8) if len(num) > 2: lab_he = cv2.cvtColor(image_orig,cv2.COLOR_BGR2LAB) else: lab_he = image_orig
