如何无损放大二进制图像?

发布于 2025-01-25 05:50:28 字数 1235 浏览 2 评论 0原文

我正在用Python创建一个随机的步行模拟。我想创建一个很酷的视频,该视频开始非常放大,然后放大以显示所有粒子。但是,我似乎无法获得图像的高分辨率。我尝试了所有cv22.列出列出的插值参数在这里和不工作。 您可以这样重新创建全尺寸框架:

frame = np.random.choice((0, 255), size=(1080, 1920))

我如何密切地放大,仍然将单个粒子视为白色正方形而不会丢失分辨率?

注1:我拥有所有的框架本身信息(即我没有从视频或类似视频中读取框架)。

注2:我正在缩放中心周围的图像阵列并调整大小,如:

def get_zoomed(frame, h_perc: float, w_perc: float):
    """given a frame and height and width percentage, return a zoomed in frame"""
    h, w = frame.shape
    h_sub = int(h * h_perc / 2)  # height of zoomed in crop
    w_sub = int(w * w_perc / 2)  # width of zoomed in crop
    center_h, center_w = (h // 2, w // 2)
    frame_crop = frame[center_h - h_sub: center_h +
                      h_sub, center_w - w_sub: center_w + w_sub]  # cropped frame
    return cv2.resize(frame_crop, (w, h), cv2.INTER_LINEAR_EXACT)

编辑:注:注:这是Inter_neart的示例图像输出

I am creating a random walk simulation with a million particles in python. I want to create a cool video which starts very zoomed in, then zooms out to show all the particles. However, I can't seem to get a high-res zoomed in image. I tried all cv2.resize interpolation arguments listed here and non worked.
You can re-create the full-size frame as such:

frame = np.random.choice((0, 255), size=(1080, 1920))

How can I zoom in very closely and still see individual particles as white squares without loosing resolution?

Note 1: I have the frame itself with all the information (i.e. I am not reading the frame from a video or something like that).

Note 2: I am zooming in by cropping the image array around the center and resizing it, as such:

def get_zoomed(frame, h_perc: float, w_perc: float):
    """given a frame and height and width percentage, return a zoomed in frame"""
    h, w = frame.shape
    h_sub = int(h * h_perc / 2)  # height of zoomed in crop
    w_sub = int(w * w_perc / 2)  # width of zoomed in crop
    center_h, center_w = (h // 2, w // 2)
    frame_crop = frame[center_h - h_sub: center_h +
                      h_sub, center_w - w_sub: center_w + w_sub]  # cropped frame
    return cv2.resize(frame_crop, (w, h), cv2.INTER_LINEAR_EXACT)

EDIT: Note 3: Here is a sample image output from INTER_NEAREST
enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

仲春光 2025-02-01 05:50:28

Christoph Rackwitz指出,插值方法需要一个关键字参数才能以我称之为函数的方式进入插值参数。

Christoph Rackwitz pointed out that a keyword argument is needed for the interpolation method to go into the interpolation parameter the way I am calling the function.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文