Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
MATLAB中的函数定义上下文_Matlab_Image Processing - Fatal编程技术网

MATLAB中的函数定义上下文

MATLAB中的函数定义上下文,matlab,image-processing,Matlab,Image Processing,我已经编写了一个MATLAB程序来为两个给定的图像渲染一个“Delta E”或色差图像。但是,当我运行程序时,我收到以下错误: 错误:文件:deltaE.m行:6列:1 在此上下文中不允许使用函数定义。 节目如下: imageOriginal = imread('1.jpg'); imageModified = imread('2.jpg'); function [imageOut] = deltaE(imageOriginal, imageModified) [imageHeight ima

我已经编写了一个MATLAB程序来为两个给定的图像渲染一个“Delta E”或色差图像。但是,当我运行程序时,我收到以下错误:

错误:文件:deltaE.m行:6列:1
在此上下文中不允许使用函数定义。

节目如下:

imageOriginal = imread('1.jpg');
imageModified = imread('2.jpg');
function [imageOut] = deltaE(imageOriginal, imageModified)

[imageHeight imageWidth imageDepth] = size(imageOriginal);

% Convert image from RGB colorspace to lab color space.
cform = makecform('srgb2lab');
labOriginal = applycform(im2double(imageOriginal),cform);
labModified = applycform(im2double(imageModified),cform);

% Extract out the color bands from the original image
% into 3 separate 2D arrays, one for each color component.
L_original = labOriginal(:, :, 1); 
a_original = labOriginal(:, :, 2); 
b_original = labOriginal(:, :, 3);

L_modified = labModified(:,:,1);
a_modified = labModified(:,:,2);
b_modified = labModified(:,:,3);

% Create the delta images: delta L, delta A, and delta B.
delta_L = L_original - L_modified;
delta_a = a_original - a_modified;
delta_b = b_original - b_modified;

% This is an image that represents the color difference.
% Delta E is the square root of the sum of the squares of the delta images.
delta_E = sqrt(delta_L .^ 2 + delta_a .^ 2 + delta_b .^ 2);

imageOut = delta_E;

end

我可能犯了一个初学者错误,因为我才17岁,我是从MATLAB开始的。如果你能告诉我我做错了什么,那就太好了。

你不能在一个函数中定义一个函数。您需要在一个单独的文件中定义函数,或者将脚本转换为(主)函数,然后您的其他函数将属于该函数。另见


编辑:在MatlabR2016B中,您可以使用脚本定义本地函数;请参阅。

从MATLAB 2016b开始,您可以在脚本中定义函数。@onewhaleid谢谢。编辑