求助~~~~python代码转c++~~~~
python新手求助转代码,下面这个函数,其他的都看得懂,就这一句M=image[i,j-1]+image[i,j]+image[i,j+1]if0<j<w-1else1...
python新手求助转代码,下面这个函数,其他的都看得懂,就这一句
M = image[i,j-1]+image[i,j]+image[i,j+1] if 0<j<w-1 else 1
语法真心混乱了,求大神解释或者直接帮忙翻译翻译吧!
def VThin(image,array):
h = image.height
w = image.width
NEXT = 1
for i in range(h):
for j in range(w):
if NEXT == 0:
NEXT = 1
else:
M = image[i,j-1]+image[i,j]+image[i,j+1] if 0<j<w-1 else 1
if image[i,j] == 0 and M != 0:
a = [0]*9
for k in range(3):
for l in range(3):
if -1<(i-1+k)<h and -1<(j-1+l)<w and image[i-1+k,j-1+l]==255:
a[k*3+l] = 1
sum = a[0]*1+a[1]*2+a[2]*4+a[3]*8+a[5]*16+a[6]*32+a[7]*64+a[8]*128
image[i,j] = array[sum]*255
if array[sum] == 1:
NEXT = 0
return image 展开
M = image[i,j-1]+image[i,j]+image[i,j+1] if 0<j<w-1 else 1
语法真心混乱了,求大神解释或者直接帮忙翻译翻译吧!
def VThin(image,array):
h = image.height
w = image.width
NEXT = 1
for i in range(h):
for j in range(w):
if NEXT == 0:
NEXT = 1
else:
M = image[i,j-1]+image[i,j]+image[i,j+1] if 0<j<w-1 else 1
if image[i,j] == 0 and M != 0:
a = [0]*9
for k in range(3):
for l in range(3):
if -1<(i-1+k)<h and -1<(j-1+l)<w and image[i-1+k,j-1+l]==255:
a[k*3+l] = 1
sum = a[0]*1+a[1]*2+a[2]*4+a[3]*8+a[5]*16+a[6]*32+a[7]*64+a[8]*128
image[i,j] = array[sum]*255
if array[sum] == 1:
NEXT = 0
return image 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询