0

I have a SDF which is a 2d numpy array and also an image feature array which is a 3d array, it has the various texture in the third dimension. So in my equation I have this:

    ux = np.sum(cv2.blur(phi0*txtre, (3, 3)))/np.sum(cv2.blur(phi0, (3, 3)))
    vx = np.sum(cv2.blur((1-phi0)*txtre, (3, 3)))/np.sum(cv2.blur((1-phi0), (3, 3)))
    a = (txtre - ux)**2
    b = (txtre - vx)**2
    dphidt = dirac(phi) * (cv2.blur((a - b), (3, 3)))

    phi += (dt * dphidt) #dt is just to maintain CFL condition

Here I have phi0 which is a heavside of SDF and is 2d array, and txtre which is a 3d array. however this line gives me broadcasting error.

Also later I need to take gradient and update the phi (SDF) with small change in phi called dphidt. So how to handle all the broadcasting?

Here dirac function is defined as follows

    def dirac(p):
    out = np.abs(p) <= 0.5
Assafs
  • 3,257
  • 4
  • 26
  • 39
lamo_738
  • 440
  • 1
  • 5
  • 15
  • Try : `cv2.blur(phi0[...,None]*txtre, (3, 3))`. – Divakar Apr 03 '17 at 09:33
  • Thanks that worked. But later in code i have : `dphidt = dirac(phi[...,None]) * (cv2.blur(c, (3, 3)))` , followed by `phi += (dt * dphidt)` for which i get an error _non-broadcastable output operand with shape (517,437,1) doesn't match the broadcast shape (517,437,20)_ – lamo_738 Apr 03 '17 at 10:04
  • Please those additional details into the question as they not readable in comments. – Divakar Apr 03 '17 at 10:06
  • yeah have updated the Question – lamo_738 Apr 03 '17 at 10:10
  • I can't comment on the edited codes, as I don't know what's `dirac`, specifically what it expects as inputs. – Divakar Apr 03 '17 at 10:14
  • @Divakar i'm sry, i have updated the Question once more – lamo_738 Apr 03 '17 at 10:35
  • For the edited codes : `dirac(phi0[...,None]) * (cv2.blur((a-b), (3, 3)))` seem to work. – Divakar Apr 03 '17 at 10:38
  • for edited code. evrything seems to work fine except the line *phi += (dt * dphidt)* . Here i get the error as i have mentioned in second comment – lamo_738 Apr 03 '17 at 11:12
  • Reading the [`docs`](https://docs.scipy.org/doc/numpy-1.10.1/user/basics.broadcasting.html) would go a long way. – Divakar Apr 03 '17 at 11:19

0 Answers0