matlab命令代码;
>> info=imfinfo('plane.jpg')
info =
Filename: 'plane.jpg'
FileModDate: '16-May-2009 10:09:02'
FileSize: 15503
Format: 'jpg'
FormatVersion: ''
Width: 640
Height: 480
BitDepth: 24
ColorType: 'truecolor'
FormatSignature: ''
NumberOfSamples: 3
CodingMethod: 'Huffman'
CodingProcess: 'Sequential'
Comment: {}
>> i=imread('plane.jpg');
>> imshow(i)
>> y=rgb2gray(i);
>> figure,imshow(y);
>> g=[-1 -1 -1; -1 8-1; -1-1-1];
??? Error using ==> vertcat
All rows in the bracketed expression must have the same
number of columns.
>> g=[-1 -1 -1; -1 8 -1 ;-1 -1 -1];
>> h=double(i);
>> j=conv2(h,g,'same');
??? Function 'conv2' is not defined for values of class 'double' and attributes 'full 3d real'.
>> j=conv2(i,g,'same');
Warning: CONV2 on values of class UINT8 is obsolete.
Use CONV2(DOUBLE(A),DOUBLE(B)) or CONV2(SINGLE(A),SINGLE(B)) instead.
> In uint8.conv2 at 11
??? Function 'conv2' is not defined for values of class 'double' and attributes 'full 3d real'.
Error in ==> uint8.conv2 at 20 ( 原因在于rgb图像是三维数组,而conv是二位操作,所以必须先转化为灰度图像)
y = conv2(varargin{:});
>> help conv2
CONV2 Two dimensional convolution.
C = CONV2(A, B) performs the 2-D convolution of matrices
A and B. If [ma,na] = size(A) and [mb,nb] = size(B), then
size(C) = [ma+mb-1,na+nb-1].
C = CONV2(H1, H2, A) convolves A first with the vector H1
along the rows and then with the vector H2 along the columns.
C = CONV2(..., SHAPE) returns a subsection of the 2-D
convolution with size specified by SHAPE:
'full' - (default) returns the full 2-D convolution,
'same' - returns the central part of the convolution
that is the same size as A.
'valid' - returns only those parts of the convolution
that are computed without the zero-padded
edges. size(C) = [ma-mb+1,na-nb+1] when
all(size(A) >= size(B)), otherwise C is
an empty matrix [].
If any of A, B, H1, and H2 are empty, then C is
an empty matrix [].
See also conv, convn, filter2 and, in the Signal Processing
Toolbox, xcorr2.
Overloaded functions or methods (ones with the same name in other directories)
help uint8/conv2.m
help uint16/conv2.m
Reference page in Help browser
doc conv2
>> j=conv2(y,g,'same');
Warning: CONV2 on values of class UINT8 is obsolete.
Use CONV2(DOUBLE(A),DOUBLE(B)) or CONV2(SINGLE(A),SINGLE(B)) instead.
> In uint8.conv2 at 11
>> h=double(y); j=conv2(h,g,'same');
>> figure ,imshow(h);title('原始图像');
>> figure ,imshow(j);title('原始图像');
>> h=double(y);
>> j=conv2(h,g,'same');
>> figure ,imshow(j);title('原始图像');
>> j=conv2(y,g,'same');
Warning: CONV2 on values of class UINT8 is obsolete.
Use CONV2(DOUBLE(A),DOUBLE(B)) or CONV2(SINGLE(A),SINGLE(B)) instead.
> In uint8.conv2 at 11
>> figure ,imshow(j);title('zhuangh图像');
>> H=fspecial('sobel');
>> I2=filter2(H,y);
>> figure,imshow(I2);
>> imwrite(y,'plane.bmp','bmp');
>> info=imfinfo('plane.bmp');
>> info (结果不尽人意,于是,我保存后检查一下图像格式,发现是'indexed' ,有点疏忽,应该调用isgray命令来分析更好)
info =
Filename: 'plane.bmp'
FileModDate: '16-May-2009 11:03:44'
FileSize: 308278
Format: 'bmp'
FormatVersion: 'Version 3 (Microsoft Windows 3.x)'
Width: 640
Height: 480
BitDepth: 8
ColorType: 'indexed'
FormatSignature: 'BM'
NumColormapEntries: 256
Colormap: [256x3 double]
RedMask: []
GreenMask: []
BlueMask: []
ImageDataOffset: 1078
BitmapHeaderSize: 40
NumPlanes: 1
CompressionType: 'none'
BitmapSize: 307200
HorzResolution: 0
VertResolution: 0
NumColorsUsed: 256
NumImportantColors: 0