保留图像中非黑色的像素

时间:2018-04-30 00:51:08

标签: python numpy opencv image-processing pixels

我想处理彩色图像并仅保留非黑色像素。我写了一些代码,但它似乎没有做我认为它正在做的事情:

super@DESKTOP MINGW64 ~/OneDrive/Documents/kibana (master)
$ yarn kbn bootstrap
yarn run v1.6.0
$ node scripts/kbn bootstrap
Running [bootstrap] command from [C:\Users\super\OneDrive\Documents\kibana]:

Found [16] projects:

kibana
├── packages
│   ├── eslint-config-kibana (@elastic/eslint-config-kibana)
│   ├── eslint-plugin-kibana-custom (@elastic/eslint-plugin-kibana-custom)
│   ├── kbn-babel-preset (@kbn/babel-preset)
│   ├── kbn-datemath (@kbn/datemath)
│   ├── kbn-dev-utils (@kbn/dev-utils)
│   ├── kbn-es (@kbn/es)
│   ├── kbn-eslint-import-resolver-kibana (@kbn/eslint-import-resolver-kibana)
│   ├── kbn-eslint-plugin-license-header (@kbn/eslint-plugin-license-header)
│   ├── kbn-plugin-generator (@kbn/plugin-generator)
│   ├── kbn-plugin-helpers (@kbn/plugin-helpers)
│   ├── kbn-pm (@kbn/pm)
│   ├── kbn-system-loader (@kbn/system-loader)
│   ├── kbn-test-subj-selector (@kbn/test-subj-selector)
│   └── kbn-ui-framework (@kbn/ui-framework)
└── x-pack

Running installs in topological order:


Installing dependencies in [@kbn/babel-preset]:


[bootstrap] failed:

Error: Command failed: yarn install --non-interactive --mutex file
    at makeError (C:\Users\super\OneDrive\Documents\kibana\packages\kbn-pm\dist\
index.js:38964:9)
    at Promise.all.then.arr (C:\Users\super\OneDrive\Documents\kibana\packages\k
bn-pm\dist\index.js:39069:16)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

黑色像素为[0,0,0],import cv2 import numpy as np import tensorly as tl def eq_svtn(T, b, M, Omega): X = 0 for i in range(3): X += b[i]*tl.fold(M[i],i,T.shape) X = X/np.sum(b) for i in range(T.shape[0]): for j in range(T.shape[1]): if Omega[i, j, :].all() != 0: X[i, j, :] = T[i, j, :] return X def silrtc(X,b,K,O): a = np.random.dirichlet(np.ones(3),size=1) a = a[0,:] M = [0, 0, 0] for i in range(K): X1 = tl.unfold(X, 0) X2 = tl.unfold(X, 1) X3 = tl.unfold(X, 2) u1, s1, v1 = LA.svd(X1, full_matrices=False) u2, s2, v2 = LA.svd(X2, full_matrices=False) u3, s3, v3 = LA.svd(X3, full_matrices=False) U = [u1,u2,u3] V = [v1,v2,v3] S = [s1,s2,s3] for j in range (3): M[j] = shrinkage_op(U[j],V[j],S[j],a[j]/b[j],X.shape) X = eq_svtn(X,b,M,O) return X im = cv2.imread('target.jpg') original_shape = im.shape zzo = np.zeros(im.shape) shp = (int(original_shape[0]),int(mt.floor(0.9*original_shape[1])),int(original_shape[2])) shp2 = (int(original_shape[0]),int(mt.ceil(0.1*original_shape[1])),int(original_shape[2])) zz = np.zeros(shp) oo = 0xFF*np.ones(shp2) cct = np.concatenate((zz,oo),1) np.random.shuffle(cct.reshape(-1, 3)) cct = cct.astype(np.uint8) im2 = np.bitwise_and(im,cct) b = [0.0001, 0.0001,0.0001] xx = silrtc(im2,b,64,cct) 为3个浮点数组,b为一组二维数组(矩阵),M为其中包含黑色像素的图像(3-D阵列,张量),T是删除了黑色像素的彩色图像。

0 个答案:

没有答案