C 中的图像/2D 数组重采样

发布于 2024-11-17 16:24:40 字数 744 浏览 7 评论 0原文

我正在寻求为 2D 数组实现重采样算法(它可以是灰度图像或某些浮点值的 2D 数组)。

此特定操作涉及的步骤是:

  1. 抗锯齿滤波)将其下采样到 8x8 或 16x16 的大小。

  2. 对此进行一些数值运算。

  3. 然后通过双线性插值将其上采样回其原始大小。

作为原型,我在 Octave 中对其进行了编码,如下所示。它给出了不错的结果。我希望获得一些有关 C 实现的参考。

fid = fopen("anti_vig_gain_map.txt","r");
fid2 = fopen("ds_us_anti_vig_gain_map.txt","w");

for i=1:1968
    for j=1:2592
       map(i,j) = fscanf(fid,'%f\n',1);

    end
end

%downsample

ds_map = imresize(map,[8 8],'linear');

%% some processing on ds_map

%upsample

us_map = imresize(ds_map,[1968 2592],'linear');

我尝试查看 imresize.m 中的代码,但一段时间后它变得复杂并且无法从中提取 C 代码。

任何指向参考 C 代码的指针,用于双线性插值来执行上采样。

还希望获得一些有关使用双线性方法的抗混叠滤波器和下采样方法的指导。

I am looking to implement a resampling algorithm for a 2D array(it could be grayscale image or some 2D array of floating point values).

The steps involved in this particular operation are:

  1. Given a 2D array, I first downsample it to size of 8x8 or 16x16, using some down-sampling method(preferably with a preceeding anti-aliasing filtering).

  2. Some nuemrical operation on this.

  3. Then upsample it back to its original size by doing, bilinear interpolation.

As a prototype I coded it as shown below in Octave. It gives decent results. I am looking to get some reference on C implementation.

fid = fopen("anti_vig_gain_map.txt","r");
fid2 = fopen("ds_us_anti_vig_gain_map.txt","w");

for i=1:1968
    for j=1:2592
       map(i,j) = fscanf(fid,'%f\n',1);

    end
end

%downsample

ds_map = imresize(map,[8 8],'linear');

%% some processing on ds_map

%upsample

us_map = imresize(ds_map,[1968 2592],'linear');

I tried to see the code in imresize.m but it gets complicated after sometime and could not extract C code out of it.

Any pointers to reference C code for bilinear interpolation to perform the upsampling.

Also looking to get some pointers for the the anti-aliasing filter and down-sampling method using bilinear method.

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

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

发布评论

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

评论(1

落花浅忆 2024-11-24 16:24:40

我认为您正在寻找的内容包含在 NetPBM 套件中。具体来说, pamscale 处理向上和向下采样,两个方向都有多种可能的滤波方案。该代码既写得很好又独立。

I think what you are looking for is contained in the NetPBM suite. Specifically, pamscale which handles both up and down sampling with multiple possible filtering schemes for both directions. The code is both well-written and self-contained.

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