循环:加载单个图像像素不是完整图像?

时间:2014-03-07 10:56:30

标签: image matlab loops pixels

我正在使用高度分辨的12位图像(650,1280)计算两点相关函数。我正在使用以下循环迭代加载每个图像

for c = 0:199;

    img = zeros(650,1280,'uint16');

    if c<10, img=imread([int2str(b),name,'000',int2str(c),'.tif']);end;
    if c>=10 && c<100, img=imread([int2str(b),name,'00',int2str(c),'.tif']);end;
    if c>=100, img=imread([int2str(b),name,'0',int2str(c),'.tif']);end;

end

+ calculate 2point correlation from the same location and averaging over the 200         

以后再进行相关函数。这个计算大约需要7分钟,等待这么长时间非常痛苦。

我的问题是否可以加载单个像素(知道它们对于两点相关的确切位置)而不是整个图像?我希望这两个对于循环中的每个图像都是相同的。

我怀疑将图像加载200次会降低我的程序速度,并且可以通过从每张图片加载特定图像像素来大大受益。

1 个答案:

答案 0 :(得分:1)

可用于Tiff图像的可选像素区域参数,用于指定要读取的像素,例如

imread('img.tif','PixelRegion',{[rowStart,rowEnd],[colStart,colEnd]})

当起始值和停止值相等时,可以读取单个像素(或行/列)。

请参阅Mathworks Documnetation以获取更全面的说明和其他示例

最后一个考虑因素 它更快吗?

clear;
tic,A=imread('test.tif');B1=A(50,50,:);toc

Elapsed time is 0.017896 seconds.

clear;
tic,B2=imread('test.tif','PixelRegion',{[50,50],[50,50]});toc

Elapsed time is 0.002447 seconds.

是...