Giter VIP home page Giter VIP logo

Comments (8)

nileshkulkarni avatar nileshkulkarni commented on June 23, 2024 1

Hi,
You can create these texture maps by treating the 3D (x,y,z) locations corresponding to each (u,v) coordinate in the texture image as the RGB value. Different permutations will give different color maps. In our case, we compute a 3D location on the unit sphere corresponding to a (u,v) value and use the (x,y,z) as the color value.

Best,

from csm.

nileshkulkarni avatar nileshkulkarni commented on June 23, 2024

Hi @linpeisensh,

We created a texture map (which is the colorful image) and then we use the predicted UV values to pick colors from the texture map and overlay them on the input image. You can have any texture map you would like, here are the color maps I used to create the colorful images. Below is my snippet

'''
Args
    img : torch.FloatTensor  C X H x W  -- this is the image
    uv_map: torch.FloatTensor H x W x 2 -- uv predictions
    uv_img: torch.FloatTensor C x H x W  -- this the texture map
    mask: torch.FloatTensor  1 x  H x W -- mask for the object
Returns
    uv_rendering: torch.FloatTensor  C x H x W
'''
def sample_UV_contour(img, uv_map, uv_img, mask, real_img=True):
    img = img.unsqueeze(0)
    uv_map = uv_map.unsqueeze(0)
    uv_img = uv_img.unsqueeze(0)
    
    uv_sample = torch.nn.functional.grid_sample(uv_img, 2*uv_map-1).squeeze(0)
    uv_sample = uv_sample*mask + (1-mask)

    # alphas = contour_alphas(uv_img.shape[2], uv_img.shape[3], real_img).unsqueeze(0)
    alphas = contour_alphas(uv_img.shape[2], uv_img.shape[3], real_img).unsqueeze(0)* 0 + 1
    # pdb.set_trace()

    alpha_sample = torch.nn.functional.grid_sample(alphas, 2*uv_map-1).squeeze(0)
    # alpha_sample = alpha_sample*0.95 + 0.05
    alpha_sample = (alpha_sample>0.0).float()*0.7
    # alpha_sample = (alpha_sample > 0.9).float()
    alpha_sample = alpha_sample*mask
    
    if real_img:
        # uv_rendering = (uv_sample*alpha_sample)*1.0 + img.squeeze(0)*(1-alpha_sample)*0.3 * (mask) + img.squeeze(0)*(1-alpha_sample)* (1-mask)*0.3
        uv_rendering = (uv_sample*alpha_sample)*1.0 + img.squeeze(0)*(1-alpha_sample)
        uv_rendering = (uv_sample*alpha_sample)*1.0 +  img.squeeze(0)*(1-alpha_sample)*0.4 * (mask) + img.squeeze(0)*(1-alpha_sample)* (1-mask)
    else:
        uv_rendering = (uv_sample*alpha_sample) + (img.squeeze(0)*(1-alpha_sample))

    return uv_rendering

Hope this helps!
Nilesh

from csm.

linpeisensh avatar linpeisensh commented on June 23, 2024

Thank you for your reply!

I will try it.

from csm.

linpeisensh avatar linpeisensh commented on June 23, 2024

Hi @nileshkulkarni,
I want to know what is contour_alphas in this function.
Thanks!

from csm.

linpeisensh avatar linpeisensh commented on June 23, 2024

And could you tell me whether I should resize uv_img? If yes, how can I do that?
Since the shape of uv_img is 102410243 (HW3) and img is 3256256 (CHW)

from csm.

nileshkulkarni avatar nileshkulkarni commented on June 23, 2024

The contour_alphas are multiplied by 0 so you can just have it as a tensor of size 1 x H x W. Sorry for not including that function as it is not required anymore

Secondly, it is fine if you have the texture image of size 3 x 1024 x 1024 you don't need to resize it as the nn.grid_sample will handle it.

from csm.

linpeisensh avatar linpeisensh commented on June 23, 2024

OK, I get the ideal result now.

Thank you very much!

from csm.

hangg7 avatar hangg7 commented on June 23, 2024

Hi @nileshkulkarni, how did you create these texture map?

from csm.

Related Issues (20)

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.