?? rgb2gray.cpp
字號:
//
// MATLAB Compiler: 3.0
// Date: Wed Apr 25 16:46:16 2007
// Arguments: "-B" "macro_default" "-O" "all" "-O" "fold_scalar_mxarrays:on"
// "-O" "fold_non_scalar_mxarrays:on" "-O" "optimize_integer_for_loops:on" "-O"
// "array_indexing:on" "-O" "optimize_conditionals:on" "-B" "sglcpp" "-p" "-W"
// "main" "-L" "Cpp" "-t" "-T" "link:exe" "-h" "libmmfile.mlib" "-W" "mainhg"
// "libmwsglm.mlib" "-l" "-p" "-W" "main" "-L" "Cpp" "-t" "-T" "link:exe" "-h"
// "libmmfile.mlib" "-h" "rgb2gray.m"
//
#include "rgb2gray.hpp"
#include "im2double.hpp"
#include "libmatlbm.hpp"
static mxChar _array1_[21] = { 'N', 'e', 'e', 'd', ' ', 'i', 'n',
'p', 'u', 't', ' ', 'a', 'r', 'g',
'u', 'm', 'e', 'n', 't', 's', '.' };
static mwArray _mxarray0_ = mclInitializeString(21, _array1_);
static mwArray _mxarray2_ = mclInitializeDouble(3.0);
static mwArray _mxarray3_ = mclInitializeDouble(1.0);
static mwArray _mxarray4_ = mclInitializeDouble(2.0);
static mxChar _array6_[26] = { 'W', 'r', 'o', 'n', 'g', ' ', 'n', 'u', 'm',
'b', 'e', 'r', ' ', 'o', 'f', ' ', 'a', 'r',
'g', 'u', 'm', 'e', 'n', 't', 's', '.' };
static mwArray _mxarray5_ = mclInitializeString(26, _array6_);
static mxChar _array8_[91] = { 'R', 'G', 'B', '2', 'G', 'R', 'A', 'Y', '(', 'R',
',', 'G', ',', 'B', ')', ' ', 'i', 's', ' ', 'a',
'n', ' ', 'o', 'b', 's', 'o', 'l', 'e', 't', 'e',
' ', 's', 'y', 'n', 't', 'a', 'x', '.', 'U', 's',
'e', ' ', 'a', ' ', 't', 'h', 'r', 'e', 'e', '-',
'd', 'i', 'm', 'e', 'n', 's', 'i', 'o', 'n', 'a',
'l', ' ', 'a', 'r', 'r', 'a', 'y', ' ', 't', 'o',
' ', 'r', 'e', 'p', 'r', 'e', 's', 'e', 'n', 't',
' ', 'R', 'G', 'B', ' ', 'i', 'm', 'a', 'g', 'e',
'.' };
static mwArray _mxarray7_ = mclInitializeString(91, _array8_);
static mxChar _array10_[38] = { 'R', ',', ' ', 'G', ',', ' ', 'a', 'n',
'd', ' ', 'B', ' ', 'm', 'u', 's', 't',
' ', 'a', 'l', 'l', ' ', 'b', 'e', ' ',
't', 'h', 'e', ' ', 's', 'a', 'm', 'e',
' ', 's', 'i', 'z', 'e', '.' };
static mwArray _mxarray9_ = mclInitializeString(38, _array10_);
static mxChar _array12_[24] = { 'I', 'n', 'v', 'a', 'l', 'i', 'd', ' ',
'i', 'n', 'p', 'u', 't', ' ', 'a', 'r',
'g', 'u', 'm', 'e', 'n', 't', 's', '.' };
static mwArray _mxarray11_ = mclInitializeString(24, _array12_);
static double _array14_[9] = { 1.0, 1.0, 1.0, .956, -.272,
-1.106, .621, -.647, 1.703 };
static mwArray _mxarray13_ = mclInitializeDoubleVector(3, 3, _array14_);
static mxChar _array16_[5] = { 'u', 'i', 'n', 't', '8' };
static mwArray _mxarray15_ = mclInitializeString(5, _array16_);
static mxChar _array18_[6] = { 'u', 'i', 'n', 't', '1', '6' };
static mwArray _mxarray17_ = mclInitializeString(6, _array18_);
static mxChar _array20_[6] = { 'd', 'o', 'u', 'b', 'l', 'e' };
static mwArray _mxarray19_ = mclInitializeString(6, _array20_);
static mwArray _mxarray21_ = mclInitializeDouble(0.0);
void InitializeModule_rgb2gray() {
}
void TerminateModule_rgb2gray() {
}
static mwArray Mrgb2gray(int nargout_, mwArray r, mwArray g, mwArray b);
_mexLocalFunctionTable _local_function_table_rgb2gray
= { 0, (mexFunctionTableEntry *)NULL };
//
// The function "rgb2gray" contains the normal interface for the "rgb2gray"
// M-function from file "d:\matlab6p5\toolbox\images\images\rgb2gray.m" (lines
// 1-72). This function processes any input arguments and passes them to the
// implementation version of the function, appearing above.
//
mwArray rgb2gray(mwArray r, mwArray g, mwArray b) {
int nargout = 1;
mwArray a = mwArray::UNDEFINED;
a = Mrgb2gray(nargout, r, g, b);
return a;
}
//
// The function "mlxRgb2gray" contains the feval interface for the "rgb2gray"
// M-function from file "d:\matlab6p5\toolbox\images\images\rgb2gray.m" (lines
// 1-72). The feval function calls the implementation version of rgb2gray
// through this function. This function processes any input arguments and
// passes them to the implementation version of the function, appearing above.
//
void mlxRgb2gray(int nlhs, mxArray * plhs[], int nrhs, mxArray * prhs[]) {
MW_BEGIN_MLX();
{
mwArray mprhs[3];
mwArray mplhs[1];
int i;
mclCppUndefineArrays(1, mplhs);
if (nlhs > 1) {
error(
mwVarargin(
mwArray(
"Run-time Error: File: rgb2gray Line: 1 Column: "
"1 The function \"rgb2gray\" was called with mor"
"e than the declared number of outputs (1).")));
}
if (nrhs > 3) {
error(
mwVarargin(
mwArray(
"Run-time Error: File: rgb2gray Line: 1 Column: "
"1 The function \"rgb2gray\" was called with mor"
"e than the declared number of inputs (3).")));
}
for (i = 0; i < 3 && i < nrhs; ++i) {
mprhs[i] = mwArray(prhs[i], 0);
}
for (; i < 3; ++i) {
mprhs[i].MakeDIN();
}
mplhs[0] = Mrgb2gray(nlhs, mprhs[0], mprhs[1], mprhs[2]);
plhs[0] = mplhs[0].FreezeData();
}
MW_END_MLX();
}
//
// The function "Mrgb2gray" is the implementation version of the "rgb2gray"
// M-function from file "d:\matlab6p5\toolbox\images\images\rgb2gray.m" (lines
// 1-72). It contains the actual compiled code for that M-function. It is a
// static function and must only be called from one of the interface functions,
// appearing below.
//
//
// function a = rgb2gray(r,g,b)
//
static mwArray Mrgb2gray(int nargout_, mwArray r, mwArray g, mwArray b) {
mclMlineEnterFunction(
"d:\\matlab6p5\\toolbox\\images\\images\\rgb2gray.m", "rgb2gray")
mwLocalFunctionTable save_local_function_table_
= &_local_function_table_rgb2gray;
int nargin_ = nargin(3, mwVarargin(r, g, b));
mwArray a = mwArray::UNDEFINED;
mwArray T = mwArray::UNDEFINED;
mwArray rgb = mwArray::UNDEFINED;
mwArray threeD = mwArray::UNDEFINED;
mwArray ans = mwArray::UNDEFINED;
//
// %RGB2GRAY Convert RGB image or colormap to grayscale.
// % RGB2GRAY converts RGB images to grayscale by eliminating the
// % hue and saturation information while retaining the
// % luminance.
// %
// % I = RGB2GRAY(RGB) converts the truecolor image RGB to the
// % grayscale intensity image I.
// %
// % NEWMAP = RGB2GRAY(MAP) returns a grayscale colormap
// % equivalent to MAP.
// %
// % Class Support
// % -------------
// % If the input is an RGB image, it can be of class uint8,
// % uint16 or double; the output image I is of the same class
// % as the input image. If the input is a colormap, the input
// % and output colormaps are both of class double.
// %
// % See also IND2GRAY, NTSC2RGB, RGB2IND, RGB2NTSC.
//
// % Copyright 1993-2002 The MathWorks, Inc.
// % $Revision: 5.20 $ $Date: 2002/03/15 15:29:04 $
//
// if nargin==0,
//
mclMline(25);
if (nargin_ == 0) {
//
// error('Need input arguments.');
//
mclMline(26);
error(mwVarargin(_mxarray0_));
//
// end
//
mclMline(27);
}
//
// threeD = (ndims(r)==3); % Determine if input includes a 3-D array
//
mclMline(28);
threeD = ndims(mwVa(r, "r")) == _mxarray2_;
//
//
// if nargin==1,
//
mclMline(30);
if (nargin_ == 1) {
//
// if threeD,
//
mclMline(31);
if (tobool(mwVv(threeD, "threeD"))) {
//
// rgb = reshape(r(:),size(r,1)*size(r,2),3);
//
mclMline(32);
rgb
= reshape(
mclArrayRef(mwVa(r, "r"), colon()),
mwVarargin(
size(mwValueVarargout(), mwVa(r, "r"), _mxarray3_)
* size(mwValueVarargout(), mwVa(r, "r"), _mxarray4_),
_mxarray2_));
//
// a = zeros([size(r,1), size(r,2)]);
//
mclMline(33);
a
= zeros(
mwVarargin(
horzcat(
mwVarargin(
size(mwValueVarargout(), mwVa(r, "r"), _mxarray3_),
size(mwValueVarargout(), mwVa(r, "r"), _mxarray4_)))));
//
// else % Colormap
//
mclMline(34);
} else {
//
// rgb = r;
//
mclMline(35);
rgb = mwVa(r, "r");
//
// a = zeros(size(r,1),1);
//
mclMline(36);
a
= zeros(
mwVarargin(
size(mwValueVarargout(), mwVa(r, "r"), _mxarray3_),
_mxarray3_));
//
// end
//
mclMline(37);
}
//
//
// elseif nargin==2,
//
mclMline(39);
} else if (nargin_ == 2) {
//
// error('Wrong number of arguments.');
//
mclMline(40);
error(mwVarargin(_mxarray5_));
//
//
// elseif nargin==3,
//
mclMline(42);
} else if (nargin_ == 3) {
//
// warning(['RGB2GRAY(R,G,B) is an obsolete syntax.',...
//
mclMline(43);
ans.EqAns(Nwarning(0, NULL, mwVarargin(_mxarray7_)));
//
// 'Use a three-dimensional array to represent RGB image.']);
// if (any(size(r)~=size(g)) | any(size(r)~=size(b))),
//
mclMline(45);
{
mwArray a_
= any(
size(mwValueVarargout(), mwVa(r, "r"))
!= size(mwValueVarargout(), mwVa(g, "g")));
if (tobool(a_)
|| tobool(
a_
| any(
size(mwValueVarargout(), mwVa(r, "r"))
!= size(mwValueVarargout(), mwVa(b, "b"))))) {
//
// error('R, G, and B must all be the same size.')
//
mclMline(46);
error(mwVarargin(_mxarray9_));
} else {
}
//
// end
//
mclMline(47);
}
//
// rgb = [r(:), g(:), b(:)];
//
mclMline(48);
rgb
= horzcat(
mwVarargin(
mclArrayRef(mwVa(r, "r"), colon()),
mclArrayRef(mwVa(g, "g"), colon()),
mclArrayRef(mwVa(b, "b"), colon())));
//
// a = zeros(size(r));
//
mclMline(49);
a = zeros(mwVarargin(size(mwValueVarargout(), mwVa(r, "r"))));
//
// else
//
mclMline(50);
} else {
//
// error('Invalid input arguments.');
//
mclMline(51);
error(mwVarargin(_mxarray11_));
//
// end
//
mclMline(52);
}
//
//
// T = inv([1.0 0.956 0.621; 1.0 -0.272 -0.647; 1.0 -1.106 1.703]);
//
mclMline(54);
T = inv(_mxarray13_);
//
//
// if isa(rgb, 'uint8')
//
mclMline(56);
if (tobool(isa(mwVv(rgb, "rgb"), _mxarray15_))) {
//
// a = uint8(reshape(double(rgb)*T(1,:)', size(a)));
//
mclMline(57);
a
= uint8_func(
reshape(
_times_transpose(
double_func(mwVv(rgb, "rgb")),
mclArrayRef(mwVv(T, "T"), _mxarray3_, colon()),
_mxarray4_),
mwVarargin(size(mwValueVarargout(), mwVv(a, "a")))));
//
// elseif isa(rgb, 'uint16')
//
mclMline(58);
} else if (tobool(isa(mwVv(rgb, "rgb"), _mxarray17_))) {
//
// a = uint16(reshape(double(rgb)*T(1,:)', size(a)));
//
mclMline(59);
a
= uint16_func(
reshape(
_times_transpose(
double_func(mwVv(rgb, "rgb")),
mclArrayRef(mwVv(T, "T"), _mxarray3_, colon()),
_mxarray4_),
mwVarargin(size(mwValueVarargout(), mwVv(a, "a")))));
//
// elseif isa(rgb, 'double')
//
mclMline(60);
} else if (tobool(isa(mwVv(rgb, "rgb"), _mxarray19_))) {
//
// a = reshape(rgb*T(1,:)', size(a));
//
mclMline(61);
a
= reshape(
_times_transpose(
mwVv(rgb, "rgb"),
mclArrayRef(mwVv(T, "T"), _mxarray3_, colon()),
_mxarray4_),
mwVarargin(size(mwValueVarargout(), mwVv(a, "a"))));
//
// a = min(max(a,0),1);
//
mclMline(62);
a = min(max(mwVv(a, "a"), _mxarray21_), _mxarray3_);
//
// end
//
mclMline(63);
}
//
//
// if ((nargin==1) & (~threeD)), % rgb2gray(MAP)
//
mclMline(65);
{
mwArray a_ = nargin_ == 1;
if (tobool(a_) && tobool(a_ & ~ mwVv(threeD, "threeD"))) {
//
// if ~isa(a, 'double')
//
mclMline(66);
if (mclNotBool(isa(mwVv(a, "a"), _mxarray19_))) {
//
// a = im2double(a);
//
mclMline(67);
a = im2double(mwVv(a, "a"));
//
// end
//
mclMline(68);
}
//
// a = [a,a,a];
//
mclMline(69);
a = horzcat(mwVarargin(mwVv(a, "a"), mwVv(a, "a"), mwVv(a, "a")));
} else {
}
//
// end
//
mclMline(70);
}
mwValidateOutput(a, 1, nargout_, "a", "rgb2gray");
mclMlineFunctionReturn()
return a;
//
//
//
mclMlineExitFunctionReturn();
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -