clc;
clear all;
close all;
A=imread('contrast (3).tif');
r=size(A,1)-1;
i=int32(rand(1,1)*r)+1; % +1 for random value always from 0
j=i+500;
if(j>size(A,1))
d=j-size(A,1);
j=j-d;
end
c=size(A,2)-1;
k=int32(rand(1,1)*c)+1; % +1 for random value always from 0
l=k+500;
if(l>size(A,2))
d1=l-size(A,2);
l=l-d1;
end
B=zeros(size(A,1),size(A,2));
x=i;
for p=i:j-1
y=k;
for q=k:l-1
B(x,y)=A(p,q);
y=y+1;
end
x=x+1;
end
B1 = mat2gray(B);
figure('Position',[10 50 1400 630]);
subplot(1,2,1),imshow(A),
ylabel('Original Image','Color','r','FontSize', 10,'FontAngle', 'italic');
subplot(1,2,2),imshow(B1),
ylabel('Sub Image','Color','r','FontSize', 10,'FontAngle', 'italic');