C 中的图像/2D 数组重采样
我正在寻求为 2D 数组实现重采样算法(它可以是灰度图像或某些浮点值的 2D 数组)。
此特定操作涉及的步骤是:
- 抗锯齿滤波)将其下采样到 8x8 或 16x16 的大小。
对此进行一些数值运算。
然后通过双线性插值将其上采样回其原始大小。
作为原型,我在 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:
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).
Some nuemrical operation on this.
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您正在寻找的内容包含在 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.