Hello, I'm working on edge detection and I want to convert a python code that runs perfectly to a matlab code because I can't call python from matlab since I don't have python installed in my own PC. I started converting the code but since I'm not familiar with python I had some difficulties to convert it all. Can you please help me out? This is the part of the python code I didn't know how to convert:

for r in range(iterations):

# approximate gradients

nabla

= [ ndimage.filters.convolve(u, w) for w in windows ]

# approximate diffusion function

diff

= [ 1./(1 + (n/kappa)**2) for n in nabla]

# update image

terms

= [diff[i]*nabla[i] for i in range(4)]

terms

+= [(1/(dd**2))*diff[i]*nabla[i] for i in range(4, 8)]

u

= u + delta*(sum(terms))

# Kernel for Gradient in x-direction

Kx = np.array(

[[-1, 0, 1], [-2, 0, 2], [-1, 0, 1]], np.int32

)

# Kernel for Gradient in y-direction

Ky = np.array(

[[1, 2, 1], [0, 0, 0], [-1, -2, -1]], np.int32

)

# Apply kernels to the image

Ix = ndimage.filters.convolve(u, Kx)

Iy = ndimage.filters.convolve(u, Ky)

Please help me converting it, I tried to understand how it works in python so I convert it to matlab but I couldn't. Thank you :)

Opportunities for recent engineering grads.

Apply Today
## 14 Comments

## Stephen Cobeldick (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/434245-how-could-i-convert-this-python-code-into-matlab#comment_647166

## Nour Sd (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/434245-how-could-i-convert-this-python-code-into-matlab#comment_647176

## Guillaume (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/434245-how-could-i-convert-this-python-code-into-matlab#comment_647193

## Nour Sd (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/434245-how-could-i-convert-this-python-code-into-matlab#comment_647202

## Guillaume (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/434245-how-could-i-convert-this-python-code-into-matlab#comment_647216

## Nour Sd (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/434245-how-could-i-convert-this-python-code-into-matlab#comment_647219

## Guillaume (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/434245-how-could-i-convert-this-python-code-into-matlab#comment_647223

## Nour Sd (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/434245-how-could-i-convert-this-python-code-into-matlab#comment_647236

## Walter Roberson (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/434245-how-could-i-convert-this-python-code-into-matlab#comment_647781

## Nour Sd (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/434245-how-could-i-convert-this-python-code-into-matlab#comment_647844

## Walter Roberson (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/434245-how-could-i-convert-this-python-code-into-matlab#comment_647971

## Nour Sd (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/434245-how-could-i-convert-this-python-code-into-matlab#comment_647985

## Walter Roberson (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/434245-how-could-i-convert-this-python-code-into-matlab#comment_647991

## Nour Sd (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/434245-how-could-i-convert-this-python-code-into-matlab#comment_647998

Sign in to comment.