Ask Your Question
0

Perform a Principle component analysis(PCA)

asked 2018-04-05 06:34:16 -0600

BhanuKiran gravatar image

I am trying to perform PCA on a binary mask of an image. Mask is of shape(480, 280) and . that looks like this

Mask=
[[0 0 0 ... 0 0 0]
 [0 0 1 ... 0 0 0]
 [0 0 1 ... 1 0 0]
 ...
 [0 0 0 ... 1 0 0]
 [0 0 0 ... 0 0 0]
 [0 0 0 ... 0 0 0]]

Value of "0" imply background and "1" imply object that i am interested in. I extract all the (x, y) of the object by

object = np.transpose(np.nonzero(Mask))
[[ 22 204]
 [ 22 205]
 [ 22 206]
 ...
 [349 115]
 [349 116]
 [349 117]]

I am not sure , how can i input this data into

mean, eigvec = cv2.PCACompute(data, None)
edit retag flag offensive close merge delete

Comments

1

you need float32 or float64 data for a PCA.

apart from that, where is the problem ?

berak gravatar imageberak ( 2018-04-05 06:59:37 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2018-04-05 08:58:38 -0600

BhanuKiran gravatar image

updated 2018-04-05 09:00:19 -0600

Yes, you are right. I didn't realize that i need to convert it to float32/float64. I just used

object = np.transpose(np.nonzero(Mask)).astype(float)
mean, eigvec = cv2.PCACompute(object, None)
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2018-04-05 06:34:16 -0600

Seen: 385 times

Last updated: Apr 05 '18