Home > Back-end >  Matlab about undefined function
Matlab about undefined function

Time:12-04

I try to write the jpeg compression code, the results have been showed undefined function or variable 'bits', use the CD command, shown in the current, folder, directory, think, I ask, is something wrong,
The code is as follows: I=imread (' scenery. BMP. BMP);
I=rgb2gray(I);
Syms quality; Syms nargchik;
Syms bit;
Y=im2jpeg (I, quality, 99);
X=jpeg2im (y);
Figure (1), imshow (I);
Figure (2), imshow (x);

M file:
Im2jpeg. M:
The function y=im2jpeg (I, quality, ~)
Narginchk (1, 3);
If ndims (I) ~=2 | | ~ isreal (I) | | ~ isnumeric (I) | | ~ isinteger (I)
Error (' The input image must be unsiged integer. ');
End
If nargin & lt; 3
Bits=8;
End
If bits<0 | | bits> 16
Error (' The input image must have 1 to 16 bits per pixel. ');
End
If nargin & lt; 2
Quality=1;
End
If quality<=0
Error (' Input parameter QUALITY must be greater than zero. ');
End
M=[16 November 10 16 to 24 40 51, 61
12 12 of 14 19 26 58, 60 55
14 and 16 24 40 57 69 56
14 of 17 to 22 51, 87, 80, 62, 29
18 and 22 and 56 68 109 103 77
24 and 35 to 55, 64, 81, 104, 113, 92
49 64 78 87 103 121 120 101
72 92 95 98 112 100 103 99];
Order=[1 2, 3, 9, 17 to 25 18 November 4 5 12 19 26 33 41
34 20 13 June 27 July 14, 21, 28, 35, 42 49 57 50 36 43
15 August 16 and 22 23 30 37 44 51 58 59 52 45 and 31
53 60, 61, 24, 32 and 46 47 54 40 48 55 62 63 64 to 56];
[xm, xn]=size (I);
I=double (I) - 2 ^ (round (bits) - 1);
T=DCTMTX (8);
Y=blockproc (I, 8 [8], 'P1 P2 * x *, t, t');
Y=blockkproc (y, 8 [8], 'round (x)/(P1)', m);
Y=im2col (y, 8 [8], 'distinct');
Xb=size (y, 2);
Y=y (order, :);
Eob=Max (y (:)) + 1;
R=zeros (numel (y) + size (y, 2), 1);
Count=0;
For j=1: xb
I=the find (y (:, j), 1, 'last');
If isempty (I)
I=0;
End
P=count + 1;
Q=p + I;
R (p, q)=[(1: I, j), y eob];
The count=count + I + 1;
End
R ((count + 1) : end)=[];
Y=struct;
Y.s considering=uint16 ([xm xn]);
Y.b its=uint16 (bits);
Y.q uality=uint16 (quality * 100);
Y.h uffman=mat2huff (r);


M file:
Jpeg2im. M
The function x=jpeg2im (y)
Narginchk (1, 1);
M=[16 November 10 16 to 24 40 51, 61
12 12 of 14 19 26 58, 60 55
14 and 16 24 40 57 69 56
14 of 17 to 22 51, 87, 80, 62, 29
18 and 22 and 56 68 109 103 77
24 and 35 to 55, 64, 81, 104, 113, 92
49 64 78 87 103 121 120 101
72 92 95 98 112 100 103 99];
Order=[1 2, 3, 9, 17 to 25 18 November 4 5 12 19 26 33
41 34 27 20 13 June 7 14, 21, 28 35 and 49 57 50
43 36 15 August 16 and 22 23 30 37 44 51 58 59 52
45 and 31 24 and 32 39 46 and 60 61 47 54 40 48 55];
Rev=order;
For k=1: length (order)
Rev (k)=find (order==k);
End
M=double (y.q uality)/100 * m;
Xb=double (y.n umblock);
Sz=double (y.s considering);
Xn=sz (2);
Xm=sz (1);
X=huff2mat (y.h uffman);
Eob=Max (x (:));
Z=zeros (64, xb); k=1;
For j=1: xb
For I=1:6 4
If x (k)==eob
k=k+1; break;
The else
Z (I, j)=x (k);
k=k+1;
End
End
End
Z=z (rev, :);
X=col2im (z, 8 [8], [xm, xn], 'distinct');
X=blockproc (x, 8 [8], 'x. * P1, m);
T=DCTMTX (8);
X=blockproc (x, 8 [8], 'P1 P2 * x *' t ', t);
X=x + double2 (2 ^ (y.b its - 1));
If y.b its<=8
X=uint8 (x);
The else
X=uint16 (x);
End



Undefined function or variable 'bits'
Error im2jpeg (line 9)
If bits<0 | | bits> 16
  • Related