Ahow to 运行 多个图像的单个matlab代码
Ahow to run single matlab code for multiple images
我有一个matlab代码。我想在一组图像上执行。
任何人都可以帮助我,运行多张图片的代码?
谢谢大家。
一个简单的代码就像对多张图片进行半色调处理。
clc;
close all;
clear all;
a=imread('lena-y.png');
inImg = double(a);
[row,col] = size(inImg);
b=zeros(row,col);
error = 0;
for i = 1: row
for j = 1 : col
outImg(i,j) =255*(inImg(i,j)>=123.6);
error = (inImg(i,j)-outImg(i,j));
if(j < col)
inImg(i,j+1) = (inImg(i,j+1) + (5/16*error));
end;
if(i < row && j >1 )
inImg(i+1,j-1) = (inImg(i+1,j-1) + (3/16 *error));
end;
if(i<row)
inImg(i+1,j) = (inImg(i+1,j) + (7/16 *error));
end;
if(j < col && i < row)
inImg(i+1,j+1) = (inImg(i+1,j+1) + (1/16 *error));
end;
end;
end;
您应该将您的代码块用作 function
。将其保存到名为 halftone.m:
的文件中
function result = halftone(I)
inImg = double(I);
[row,col] = size(inImg);
...
...
end
这允许您在任意数量的图像上调用此函数,因此您只需读入它们并在不同的脚本中轻松调用它:
a=imread('lena-y.png');
result_a = halftone(a);
b=imread('another-image.png');
result_b = halftone(b);
有关脚本、函数和在 matlab 中编写程序的更多信息,请参阅本教程:http://uk.mathworks.com/videos/writing-a-matlab-program-69023.html
我有一个matlab代码。我想在一组图像上执行。 任何人都可以帮助我,运行多张图片的代码?
谢谢大家。
一个简单的代码就像对多张图片进行半色调处理。
clc;
close all;
clear all;
a=imread('lena-y.png');
inImg = double(a);
[row,col] = size(inImg);
b=zeros(row,col);
error = 0;
for i = 1: row
for j = 1 : col
outImg(i,j) =255*(inImg(i,j)>=123.6);
error = (inImg(i,j)-outImg(i,j));
if(j < col)
inImg(i,j+1) = (inImg(i,j+1) + (5/16*error));
end;
if(i < row && j >1 )
inImg(i+1,j-1) = (inImg(i+1,j-1) + (3/16 *error));
end;
if(i<row)
inImg(i+1,j) = (inImg(i+1,j) + (7/16 *error));
end;
if(j < col && i < row)
inImg(i+1,j+1) = (inImg(i+1,j+1) + (1/16 *error));
end;
end;
end;
您应该将您的代码块用作 function
。将其保存到名为 halftone.m:
function result = halftone(I)
inImg = double(I);
[row,col] = size(inImg);
...
...
end
这允许您在任意数量的图像上调用此函数,因此您只需读入它们并在不同的脚本中轻松调用它:
a=imread('lena-y.png');
result_a = halftone(a);
b=imread('another-image.png');
result_b = halftone(b);
有关脚本、函数和在 matlab 中编写程序的更多信息,请参阅本教程:http://uk.mathworks.com/videos/writing-a-matlab-program-69023.html