balthazarneveu / blind-deblurring-from-synthetic-data

MVA ENS Paris Saclay - Image restoration project on deblurring learnt on deadleaves
3 stars 0 forks source link

Add more primitives to synthetic charts #27

Open balthazarneveu opened 3 months ago

balthazarneveu commented 3 months ago

Image

@cuda.jit(cache=False)
def cuda_dead_leaves_gen_reversed(generation, centers, radia, colors, background):
    idx, idy, c = cuda.grid(3)
    ny, nx, nc = generation.shape

    n_discs = centers.shape[0]

    # Out of bound threads
    if idx >= nx or idy >= ny:
        return

    for disc_id in range(n_discs):
        dx = idx - centers[disc_id, 0]
        dy = idy - centers[disc_id, 1]
        dist_sq = dx*dx + dy*dy

        # Naive thread diverging version
        r = radia[disc_id]
        r_sq = r*r

        if (disc_id % 4) == 0 and dist_sq <= r_sq:
            # Copy back to global memory
            alpha = dist_sq/r_sq
            generation[idy, idx, c] = colors[disc_id, c] * alpha + colors[disc_id, (c+1) % 3] * (1-alpha)
            return
        elif (disc_id % 4) == 1 and (abs(dx)+abs(dy)) <= r:
            # Copy back to global memory
            alpha = dist_sq/r_sq
            generation[idy, idx, c] = colors[disc_id, c] * alpha + colors[disc_id, (c+1) % 3] * (1-alpha)
            return
        elif (disc_id % 4) == 2 and abs(dx) <= r and abs(dy) <= r:
            generation[idy, idx, c] = colors[disc_id, c]
            return
        elif (disc_id % 200) == 3 and abs(dy) <= r//5:
            generation[idy, idx, c] = colors[disc_id, c] * alpha + colors[disc_id, (c+1) % 3] * (1-alpha)
            return
        elif (disc_id % 200) == 4 and abs(dx) <= r//5:
            generation[idy, idx, c] = colors[disc_id, c] * alpha + colors[disc_id, (c+1) % 3] * (1-alpha)
            return
    generation[idy, idx, c] = background[c]
balthazarneveu commented 2 months ago

Code stored at 27-random-lines-sqares-primitives

balthazarneveu commented 2 months ago