w1 = [1 0 -1; 0 0 0; -1 0 1];
w2 = [1 0 1; 0 -4 0; 1 0 1];
w3 = [-1 -1 -1; -1 8 -1; -1 -1 -1];
m=480; n=480;
fin=fopen('arrayR.raw','r');
X=fread(fin,m*n,'uint8=>uint8'); fclose(fin);
Y=reshape(X,m,n);
Y=Y';
figure;subplot(1,3,1);
t1 = conv2(w1, Y);
t1 = round(-140 + 255*(t1 - min(t1(:)))/(max(t1(:)) - min(t1(:))));
imshow(t1);subplot(1,3,2);
t2 = conv2(w2, Y);
t2 = round(-150 + 255*(t2 - min(t2(:)))/(max(t2(:)) - min(t2(:))));
imshow(t2);
subplot(1,3,3);
t3 = conv2(w3, Y);
t3 = round(-65 + 255*(t3 - min(t3(:)))/(max(t3(:)) - min(t3(:))));
imshow(t3);

m=480; n=640;
fin=fopen('gelm1.raw','r');
X=fread(fin,m*n,'uint8=>uint8'); fclose(fin);
Y=reshape(X,m,n);
Y=Y';
figure;
subplot(1,3,1);
t1 = conv2(w1, Y);
t1 = round(-120 + 255*(t1 - min(t1(:)))/(max(t1(:)) - min(t1(:))));
imshow(t1);
subplot(1,3,2);
t2 = conv2(w2, Y);
t2 = round(-152 + 255*(t2 - min(t2(:)))/(max(t2(:)) - min(t2(:))));
imshow(t2);
subplot(1,3,3);
t3 = conv2(w3, Y);
t3 = round(-65 + 255*(t3 - min(t3(:)))/(max(t3(:)) - min(t3(:))));
imshow(t3);

m=512; n=512;
fin=fopen('mandrill.raw','r');
X=fread(fin,m*n,'uint8=>uint8'); fclose(fin);
Y=reshape(X,m,n);
Y=Y';
figure;
subplot(1,3,1);
t1 = conv2(w1, Y);
t1 = round(-115 + 255*(t1 - min(t1(:)))/(max(t1(:)) - min(t1(:))));
imshow(t1);
subplot(1,3,2);
t2 = conv2(w2, Y);
t2 = round(-152 + 255*(t2 - min(t2(:)))/(max(t2(:)) - min(t2(:))));
imshow(t2);
subplot(1,3,3);
t3 = conv2(w3, Y);
t3 = round(-65 + 255*(t3 - min(t3(:)))/(max(t3(:)) - min(t3(:))));
imshow(t3);

m=512; n=512;
fin=fopen('peppers.raw','r');
X=fread(fin,m*n,'uint8=>uint8'); fclose(fin);
Y=reshape(X,m,n);
Y=Y';
figure;
subplot(1,3,1);
t1 = conv2(w1, Y);
t1 = round(-115 + 255*(t1 - min(t1(:)))/(max(t1(:)) - min(t1(:))));
imshow(t1);
subplot(1,3,2);
t2 = conv2(w2, Y);
t2 = round(-152 + 255*(t2 - min(t2(:)))/(max(t2(:)) - min(t2(:))));
imshow(t2);
subplot(1,3,3);
t3 = conv2(w3, Y);
t3 = round(-85 + 255*(t3 - min(t3(:)))/(max(t3(:)) - min(t3(:))));
imshow(t3);