【发布时间】:2014-09-13 13:10:19
【问题描述】:
我正在尝试在 matlab 中编写一个函数,该函数将返回一个缩小到大小的图像MS = 原始图像中的 x 分辨率长度和NS= 原始图像中 y 分辨率的长度,使用最接近的邻居公式。
我遇到了一个越界异常,并且在确定解决方案时遇到了一些困难。我认为我需要另一个条件检查。目前,对于我的图像,它正在尝试访问 d(1309,27),但是它不应该访问该值,因为它在 for 循环中是有界的 M 和 N:for ms = 1:M
function r = imaging( s, M, N, L )
%imaging Computes the acquisition of the image
s= imread('Z:\file.tif');
figure, imshow(s);
d = im2double(s);
[MS, NS] = size(d);
M = 400;
N = 100;
dx = M/MS;
dy = N/NS;
for ms = 1:M
mp= floor( (ms +0.5)/dx ) ;
for ns = 1:N
if(d(ms,ns))
np= floor( (ns +0.5)/dy ) ;
r(ms,ns)= d(mp,np);
end
end
end
【问题讨论】:
-
为什么不使用
imresize? -
我基本上是在学习 imresize 背后的功能。它是作为一项任务分配的,所以我不是在寻找可行的解决方案,而是寻求正确解决方案的帮助。
标签: image matlab nearest-neighbor