SourceForge has been redesigned. Learn more.
Close

[07d29c]: / testimio.m  Maximize  Restore  History

Download this file

57 lines (53 with data), 1.6 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
## This program is public domain.
## build image for image r/w tests
x=linspace(-8,8,200);
[xx,yy]=meshgrid(x,x);
r=sqrt(xx.^2+yy.^2) + eps;
map=colormap(hsv);
A=sin(r)./r;
minval = min(A(:));
maxval = max(A(:));
z = round ((A-minval)/(maxval - minval) * (rows(colormap) - 1)) + 1;
Rw=Gw=Bw=z;
Rw(:)=fix(255*map(z,1));
Gw(:)=fix(255*map(z,2));
Bw(:)=fix(255*map(z,3));
Aw=fix(255*(1-r/max(r(:)))); ## Fade to nothing at the corners
if exist("jpgwrite")
disp(">jpgwrite");
jpgwrite('test.jpg',Rw,Gw,Bw);
stats=stat("test.jpg");
assert(stats.size,6423);
disp(">jpgread");
im = jpgread('test.jpg');
Rr = im(:,:,1); Gr = im(:,:,2); Br = im(:,:,3);
assert(all(Rw(:)-double(Rr(:))<35));
assert(all(Gw(:)-double(Gr(:))<35));
assert(all(Bw(:)-double(Br(:))<35));
unlink('test.jpg');
else
disp(">jpgread ... not available");
disp(">jpgwrite ... not available");
endif
if exist("pngwrite")
disp(">pngwrite");
pngwrite('test.png',Rw,Gw,Bw,Aw);
stats=stat("test.png");
assert(stats.size,24738);
disp(">pngread");
im = pngread('test.png');
Rr = im(:,:,1); Gr = im(:,:,2); Br = im(:,:,3);
assert(all(double(Rr(:))==Rw(:)));
assert(all(double(Gr(:))==Gw(:)));
assert(all(double(Br(:))==Bw(:)));
[im,Ar] = pngread('test.png');
Rr = im(:,:,1); Gr = im(:,:,2); Br = im(:,:,3);
assert(all(double(Rr(:))==Rw(:)));
assert(all(double(Gr(:))==Gw(:)));
assert(all(double(Br(:))==Bw(:)));
assert(all(double(Ar(:))==Aw(:)));
unlink('test.png');
else
disp(">pngread ... not available");
disp(">pngwrite ... not available");
endif