如何无损放大二进制图像?
我正在用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)
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
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.