在Matlab中进行升采样 [英] upsampling in matlab

查看:1158
本文介绍了在Matlab中进行升采样的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试编写一个matlab函数,对我的图片进行升采样(灰度值矩阵).实际上,这并不是什么复杂的事情,但是我还是做错了. 我的目标是将其大小调整2倍,一开始我只想看一下我放大的图片.我想用零填充空白,因此每个第二行/列都填充有零. 当我完成后,我想知道为什么我只看到像素的灰色海洋.我希望能够至少识别出我的照片中的一些东西.

I try to write a matlab function that upsamples me a picture (matrix of grey values). It is actually nothing overwhelmingly complicated, but I yet manage to do it wrong. My objective is it to resize it by factor 2 and for the start I just want to see my upscaled picture. I want to fill the gaps with zeros, hence every 2nd row/column is a filled with zeros. When I am done, I wonder why I see nothing but a grey ocean of pixels. I would have expected to be able to recognize at least some stuff in my picture.

这是我的职责,有人看到我的错误吗?

Here is my function, does anyone see my mistake?

function [upsampled] = do_my_upsampling(image)
    [X Y] = size(image);
    upsampled = zeros(X*2, Y*2);
    upsampled(1:2:end, 1:2:end) = image(1:1:end, 1:1:end);
end

推荐答案

您的代码对我来说很好(使用image = rand(100);.但是,这不是获得结果的Matlab方式.

Your code works fine for me (with image = rand(100);. However, it's not a very Matlab-way to achieve the result.

如果您只想散布像素,为什么不直接索引呢?

If you just want to spread out your pixels, why don't you do direct indexing?

[nRows,nCols] = size(image);
upsampled = zeros(2*nRows,2*nCols);
upsampled(1:2:end,1:2:end) = image;

这篇关于在Matlab中进行升采样的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆