Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nail.py code. TypeError, IndexError #1

Open
HyunmokMoon opened this issue Apr 25, 2017 · 4 comments
Open

nail.py code. TypeError, IndexError #1

HyunmokMoon opened this issue Apr 25, 2017 · 4 comments

Comments

@HyunmokMoon
Copy link

HyunmokMoon commented Apr 25, 2017

Hi,

in nail.py I've got this error. TypeError and IndexError.

$ python nail.py
Traceback (most recent call last):
File "nail.py", line 61, in
x, y = getInteriorPoints(x, y)
File "nail.py", line 30, in getInteriorPoints
ext(amin(ylist), amax(ylist), i)
File "nail.py", line 24, in ext
naily.extend((ones(b-a)*i).tolist())
File "/usr/local/lib/python2.7/dist-packages/numpy/core/numeric.py", line 192, in ones
a = empty(shape, dtype, order)
TypeError: 'float' object cannot be interpreted as an index

I resolved this line change.
#a, b=round(a), round(b)
a = int (round(a))
b = int (round(b))

After that, I also got error message. IndexError.

Traceback (most recent call last):
File "nail.py", line 65, in
applyTexture(x, y)
File "nail.py", line 52, in applyTexture
val2 = color.rgb2lab((im[x, y]/255.).reshape(len(x), 1, 3)).reshape(len(x), 3)
IndexError: only integers, slices (:), ellipsis (...), numpy.newaxis (None) and integer or boolean arrays are valid indices

I resolved by int value.
apply x list to int type.

change to int type

int_x = map(int,x)
int_y = map(int,y)

and use int_x lather than x, int_y lather than y.
val2 = color.rgb2lab((im[int_x, int_y]/255.).reshape(len(int_x), 1, 3)).reshape(len(int_x), 3)

this line also replaced.
x substituted by int_x and y by int_y
im[int_x, int_y] = color.lab2rgb(val2.reshape(len(int_x), 1, 3)).reshape(len(int_x), 3)*255

then I can see result image.
in Ubuntu 16.10
python 2.7

blush.py is ok. but lipstick.py is also same issue. Maybe this change also could be applied to lipstick.py file.

I share for others.
Thank you.

in python 3 map function have to change little bit different way.
http://stackoverflow.com/questions/7368789/convert-all-strings-in-a-list-to-int

@antonov7
Copy link

antonov7 commented Jul 2, 2017

Hello HyunmokMoon,

I'm trying to make lipstick.py work. I have same error as you had with nail.py. I followed your advice and changed to int type, but still got the error:

Traceback (most recent call last):
File "lipstick.py", line 77, in
val = color.rgb2lab((im[int_x,int_y]/255.).reshape(len(int_x),1,3)).reshape(len(int_x),3)
IndexError: only integers, slices (:), ellipsis (...), numpy.newaxis (None) and integer or boolean arrays are valid indices

Any new advice on how to make it work?? I'm new to python and can't step over this error. Here is my modified code:

x = [] #will contain the x coordinates of points on lips
y = [] #will contain the y coordinates of points on lips

int_x = map(int,x)
int_y = map(int,y)

def ext(a,b,i):
a=int(round(a))
b=int(round(b))
#print(arange(a,b,1))
int_x.extend(arange(a,b,1).tolist())
int_y.extend((ones(b-a)*i).tolist())

for i in range(int(o_u_l[1][0]),int(i_u_l[1][0]+1)):
ext(o_u_l0,o_l0+1,i)

for i in range(int(i_u_l[1][0]),int(o_u_l[1][-1]+1)):
ext(o_u_l0,i_u_l0+1,i)
ext(i_l0,o_l0+1,i)

for i in range(int(i_u_r[1][-1]),int(o_u_r[1][-1]+1)):
ext(o_u_r0,o_l0+1,i)

for i in range(int(i_u_r[1][0]),int(i_u_r[1][-1]+1)):
ext(o_u_r0,i_u_r0+1,i)
ext(i_l0,o_l0+1,i)

val = color.rgb2lab((im[int_x,int_y]/255.).reshape(len(int_x),1,3)).reshape(len(int_x),3)
L,A,B = mean(val[:,0]),mean(val[:,1]),mean(val[:,2])
L1,A1,B1 = color.rgb2lab(np.array((r/255.,g/255.,b/255.)).reshape(1,1,3)).reshape(3,)
ll,aa,bb = L1-L,A1-A,B1-B
val[:,0] += ll
val[:,1] += aa
val[:,2] += bb
#val[:,0] = np.clip(val[:,0], 0, 100)
#val[:,1] = np.clip(val[:,1], -127, 128)
#val[:,2] = np.clip(val[:,2], -127, 128)

im[int_x,int_y] = color.lab2rgb(val.reshape(len(int_x),1,3)).reshape(len(int_x),3)*255
gca().set_aspect('equal', adjustable='box')
imshow(im)
show()
imsave('output.jpg',im)

Many thanks!!

@antonov7
Copy link

antonov7 commented Jul 2, 2017

Problem solved. Was my bad : int_x and int_y moved after x and y took the values:

x = []
y = []

def ext(a,b,i):
a=int(round(a))
b=int(round(b))
#print(arange(a,b,1))
int_x.extend(arange(a,b,1).tolist())
int_y.extend((ones(b-a)*i).tolist())

int_x = map(int,x)
int_y = map(int,y)

@annisaabuhamid
Copy link

hello @antonov7 i tried your suggested solution but it doesnt work for me

@corbinyo
Copy link

corbinyo commented Apr 2, 2018

Yes, this is not working for me either. @antonov7 - any other suggestions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants