Giter Site home page Giter Site logo

Comments (6)

parkgeonwo avatar parkgeonwo commented on July 30, 2024

When I transform the eyes, I want only the eyes to be transformed, not the entire image.

from pychubby.

jankrepl avatar jankrepl commented on July 30, 2024

Hey there! And thank you for your interest!

That is actually a great question:) pychubby is built on top of a "4 corners logic". That means that the 4 corners will never be displaced. However, very often points on the edges are going to be displaced and it will lead to these black regions. Note that if it was not the case even weirder artefacts might show up.

Anyway, possible solutions

  1. Just crop the final image so that the black regions on the edges are not visible
  2. Get all the perfectly black pixels (RGB=(0, 0, 0)) and replace them with some other color. A cleaner way of doing this would be passing a custom color in cv.remap when doing the warping.
    warped_img = cv2.remap(img, tform_x, tform_y, order)
  3. Completely change the logic of pychubby and make sure that pixels on the edge of the image are not displaced

I would go for the first option:)

Hope that helps:)

from pychubby.

parkgeonwo avatar parkgeonwo commented on July 30, 2024

Thank you for answer. Do you know how to prevent the pixels on the edges from being deformed?
Methods 1 and 2 do not seem to be able to solve my problem now.

from pychubby.

jankrepl avatar jankrepl commented on July 30, 2024

Well, you would need to modify the source code. See below exactly the lines which implement the "fixed points" logic. Currently, it only "anchors" the 4 corners.

if anchor_corners:
corners = np.array([[0, 0],
[0, shape[0] - 1],
[shape[1] - 1, 0],
[shape[1] - 1, shape[0] - 1]])
new_points = np.vstack([new_points, corners])
old_points = np.vstack([old_points, corners])
points_delta_x = np.concatenate([points_delta_x, [0, 0, 0, 0]])
points_delta_y = np.concatenate([points_delta_y, [0, 0, 0, 0]])

See below a sketch of a possible change

Screenshot 2022-10-06 at 15 57 25

I guess you would have to play around and experiment a bit and see for yourself. You can add as many fixed points as you want. Note that by specifying these fixed points you are basically forcing the displacement at those given points to be 0.

Hope that makes sense:)

from pychubby.

parkgeonwo avatar parkgeonwo commented on July 30, 2024

Transforming by adding anchor points at 50px spacing to each corner solved the problem. Thank you so very much.

corners_list = []
corners_list.append([0, 0])
corners_list.append([0, shape[0] -1])   # 0,y
corners_list.append([shape[1] -1, 0])   # x,0
corners_list.append([shape[1] -1, shape[0] -1])   # x,y

for i in range(1, shape[0]-1, 50):
    corners_list.append([0,i])
    corners_list.append([shape[1]-1,i])
for i in range(1, shape[1]-1, 50): 
    corners_list.append([i,0])
    corners_list.append([i,shape[0]-1])   

# print(shape[0], shape[1])
# print(corners_list)

if anchor_corners:
    corners = np.array(corners_list)  
    new_points = np.vstack([new_points, corners])
    old_points = np.vstack([old_points, corners])
    points_delta_x = np.concatenate([points_delta_x, [0 for i in range(len(corners_list))]]) 
    points_delta_y = np.concatenate([points_delta_y, [0 for i in range(len(corners_list))]])

from pychubby.

jankrepl avatar jankrepl commented on July 30, 2024

Great!

from pychubby.

Related Issues (19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.