pyton code, to convert , cylinder object from plain image . instead of photoshop

after croping in mspaint, free form select.

image2












 import cv2

import numpy as np

from google.colab import files

from PIL import Image


# Paths

input_image_path = "/content/image1.png"   # banner

reference_path   = "/content/image2.png"   # curved shape

output_path      = "/content/image3.png"   # output


# Load images

img = cv2.imread(input_image_path)

ref = cv2.imread(reference_path)


# Get dimensions

h, w = img.shape[:2]


# Cylindrical warp function

def cylindrical_warp(img, f):

    """Warp image into cylindrical projection"""

    h, w = img.shape[:2]

    # coordinate grid

    y_i, x_i = np.indices((h, w))

    x_c = w / 2

    y_c = h / 2

    # cylindrical coords

    theta = (x_i - x_c) / f

    h_ = (y_i - y_c) / f

    X = np.sin(theta)

    Y = h_

    Z = np.cos(theta)

    x_ = f * X / Z + x_c

    y_ = f * Y / Z + y_c

    # map

    map_x = x_.astype(np.float32)

    map_y = y_.astype(np.float32)

    return cv2.remap(img, map_x, map_y, cv2.INTER_LINEAR)


# Apply warp (adjust focal length f for more/less curve)

focal_length = w  # try smaller values for more curve

warped = cylindrical_warp(img, focal_length)


# Resize warped to match reference width

warped_resized = cv2.resize(warped, (ref.shape[1], ref.shape[0]))


# Save output

cv2.imwrite(output_path, warped_resized)


# Show in colab

Image.open(output_path).show()

print("✅ Saved as", output_path)


Popular posts from this blog

SAP CPI : camle expression in sap cpi , cm, router, filter and groovy script. format

SAP CPI camel conditions and xpath conditions

oauth call to cpi integraiton suite from sap apim