OpenCores
URL https://opencores.org/ocsvn/mkjpeg/mkjpeg/trunk

Subversion Repositories mkjpeg

[/] [mkjpeg/] [trunk/] [tb/] [matlab/] [img2txt.m] - Blame information for rev 49

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 25 mikel262
filename='test';
2
filenamet=strcat(filename,'.txt');
3
 
4
I = imread(filename,'bmp');
5
 
6
IYUV=rgb2ycbcr(I);
7
 
8
fid = fopen(filenamet,'w+');
9
[X,Y,Z] = size(I);
10
fprintf(fid, '%d\n',Z);  % number of image components
11
fprintf(fid, '%d\n',X);  % lines
12
fprintf(fid, '%d\n',Y);  % pixels in line
13
for x = 1:X
14
   for y = 1:Y
15
     for z = 1:Z
16
       R = int16(I(x,y,1));
17
       G = int16(I(x,y,2));
18
       B = int16(I(x,y,3));
19
       % Y
20
       if z == 1
21
         sample = (0.299*R)+(0.587*G)+(0.114*B);
22
       % Cb
23
       elseif z == 2
24
         sample = (-0.1687*R)-(0.3313*G)+(0.5*B)+128;
25
       % Cr
26
       elseif z == 3
27
         sample = (0.5*R)-(0.4187*G)-(0.0813*B)+128;
28
       end
29
       if sample > 255
30
         sample = 255;
31
       elseif sample < 0
32
         sample = 0;
33
       end
34
       ID(x,y,z) = sample;
35
 
36
       %sample = IYUV(x,y,z);
37
       sample = I(x,y,z);
38
 
39
       if sample < 16
40
         fprintf(fid, '0%x', double(sample));
41
       else
42
         fprintf(fid, '%x', double(sample));
43
       end;
44
        end;
45
   end;
46
   fprintf(fid,'\n');
47
end;
48
fclose(fid);

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.