2009-07-21 217 views
-1
位图图像

我已在computer.I图像文件夹中的BMP图片来自1.bmp命名它100.bmp他们的。所有尺寸为576 * 768加快节能情节人物在MATLAB

我读一个我从一百幅图像中选择矩形区域。矩形区域的像素坐标从垂直方向从182变为281,水平方向从426变为639.我保存了代表矩形中所有像素坐标中图像之间交换像素值的图形区域到另一个文件

我米文件是如下:

pixvalue=zeros(100); 
j=1 ;% will represent pixel coordinate sequence 
% find pizel coordinates in rectangular region 
for y=182:281 
     for x=426:639 
      for i=1:100 
      % read images 
     s = sprintf('C:\\images\\%d.bmp', i); 
     A = imread(s); 
     A=double(A); 
     pixvalue(i)= A(y,x); 
     end 
     s2=sprintf('%d.plot', j); 
     f=figure('visible','off'), 
     plot(pixvalue); 
     xlabel('images'); 
     ylabel('pixvalue'); 
     title(s2); 
     s3=sprintf('C:\\registration\\%d.bmp', j); 

     %% save figures as 8 bit bitmap to file 
     print(f,'-dbmp256',s3); 
     j=j+1; 
     end 
    end 

不幸的是,这段代码一直在工作vey vey慢!我如何加速它?

问候......

回答

1

你是(281-182)*(639-426)次读取相同的图像..

也许你应该阅读这一次循环之前的所有图像。将它存储在一些变量中。

比你应该做你必须做..

类似:

for i=1:100 
    % read images 
    s = sprintf('C:\\images\\%d.bmp', i); 
    A(i) = imread(s); 
end 

for x=... 
    for y=... 
     for i=1:100 
      pixvalue(i)= A(i, y, x); 
     end 
    end 

     .. 
     .. 

其实我不记得了MATLAB语法很好,但一定要仔细阅读所有imagesin一个在这个大循环之前循环。这里我更正了代码。

比在大循环中使用A(i)代替A.

ps。顺便说一句,我优化它,就好像以前的代码工作..我没有一个matlab现在试试..

+0

ufukgun,这里有个问题。 IMREAD返回的图像是2-D(或潜在的3-D)数组。你将不得不将它们存储在一个多维数组或单元格数组中......像这样的二维图像:A(:,:,i)= imread(s); – gnovice 2009-07-21 15:10:25

+0

是的你是对的。但我认为它应该自动将其存储在多维数组中。 实际上,我现在没有在我的电脑上使用matlab,所以我正在回答,因为我记得.. – ufukgun 2009-07-21 15:14:50

1

您的代码可以分为两部分。首先,您要加载图像数据并保存每个图像的子区域的像素值。这可以用下面的代码来完成:

subRegion = zeros(100,214,100); % 3-D matrix to store image subregions 
for i = 1:100, 
    s = ['C:\images\' int2str(i) '.bmp'];  % Create file name string 
    A = double(imread(s)); % Load image and convert to double precision 
    subRegion(:,:,i) = A(182:281,426:639); % Store subregion of image 
end 

接下来,看来要绘制每个像素值在所有的图像,并输出积到一个文件中。这是很多的图像文件(21,400!),势必需要一段时间才能运行。如果你确定你想这样做,这里有一种方法:

j = 1; % Pixel index 
for y = 1:100, % Loop over rows 
    for x = 1:214, % Loop over columns 
    hFigure = figure('Visible','off'); 
    data = subRegion(y,x,:); % Get pixel value from all 100 images 
    plot(data(:)); 
    xlabel('images'); 
    ylabel('pixvalue'); 
    title(['Plot ' int2str(j)]); 
    outFile = ['C:\registration\' int2str(j) '.bmp']; 
    print(hFigure,'-dbmp256',outFile); % Save figure 
    j = j+1; 
    end 
end