function cc = c_images(uid,JSONString)


pkg load image


format long;
aswq = 1
JSONSentinel = JSONString;

TileMaxLat =JSONSentinel.TileMaxLat
TileMinLat =JSONSentinel.TileMinLat
TileMaxLong = JSONSentinel.TileMaxLong
TileMinLong =JSONSentinel.TileMinLong

FieldMaxLat = JSONSentinel.FieldMaxLat
FieldMinLat = JSONSentinel.FieldMinLat
FieldMaxLong =JSONSentinel.FieldMaxLong
FieldMinLong =JSONSentinel.FieldMinLong

FieldLatLen = FieldMaxLat-FieldMinLat
FieldLongLen = FieldMaxLong-FieldMinLong

MGRS = JSONSentinel.MGRS


TCIFileName = strcat('TileTCI_',MGRS);
TCIFileName = strcat(TCIFileName,'.jp2');

TCI = imread(TCIFileName);
sizeB4 = [10980 10980]
topleftpix = TCI(1,1,1)
bottomleftpix = TCI(10980,1,1)
toprightpix = TCI(1,10980,1)
bottomrightpix = TCI(10980,10980,1)
if topleftpix==0 & bottomleftpix==0
	for ww = 1:sizeB4(1)
		if TCI(sizeB4(1),ww,1)==0
			aqqw = 1;
		else
			TileStartPixel = ww
			TileEndPixel = sizeB4(1)
			break;
		end
	end
elseif toprightpix==0 & bottomrightpix==0
	for ww = 1:sizeB4(1)
		if TCI(1,ww,1)==0
			TileStartPixel = 1
			TileEndPixel = ww
			break;
		else
			aqqw =1;
		end
	end
else
	TileStartPixel = 1
	TileEndPixel = sizeB4(1)
end
	
TileLonPixelLength = TileEndPixel-TileStartPixel
TileLatPixelLength = 10980
PixelsPerLong = TileLonPixelLength/(TileMaxLong-TileMinLong)
PixelsPerLat = 10980/(TileMaxLat-TileMinLat)
FieldPixelLatLen = round(PixelsPerLat*FieldLatLen)
FieldPixelLongLen = round(PixelsPerLong*FieldLongLen)

if FieldPixelLatLen<10
	FieldPixelLatLen=FieldPixelLatLen+5
elseif FieldPixelLatLen>10 & FieldPixelLatLen<50
	FieldPixelLatLen = FieldPixelLatLen+10
else
	FieldPixelLatLen = FieldPixelLatLen+20
end

if FieldPixelLongLen<10
	FieldPixelLongLen=FieldPixelLongLen+5
elseif FieldPixelLongLen>10 & FieldPixelLongLen<50
	FieldPixelLongLen = FieldPixelLongLen+10
else
	FieldPixelLongLen = FieldPixelLongLen+20
end


filenametci = strcat(uid,"_TCI.png");
tci = imread(filenametci);
filenameetci = strcat(uid,"_ETCI.png");
etci = imread(filenameetci);
filenamemndvi = strcat(uid,"_mndvi.png");
mndvi = imread(filenamemndvi);
filenamemndwi = strcat(uid,"_mndwi.png");
mndwi = imread(filenamemndwi);
filenamendvi = strcat(uid,"_ndvi.png");
ndvi = imread(filenamendvi);
filenamendwi = strcat(uid,"_ndwi.png");
ndwi = imread(filenamendwi);
filenamendre = strcat(uid,"_ndre.png");
ndre = imread(filenamendre);
filenamemndre = strcat(uid,"_mndre.png");
mndre = imread(filenamemndre);


sizeTCI = size(tci)
centerxTCI = round(sizeTCI(1)/2)
centeryTCI = round(sizeTCI(2)/2)
xstart = centerxTCI-round(FieldPixelLongLen/2)
xend = centerxTCI+round(FieldPixelLongLen/2)
ystart = centeryTCI-round(FieldPixelLatLen/2)
yend = centeryTCI+round(FieldPixelLatLen/2)

aee = 0
tci = tci(xstart:xend,ystart:yend,:);
aee = 1

TCIgray = rgb2gray(tci);
sizegray = size(TCIgray);
graycount = 0;
for i = 1:sizegray(1)
	for j = 1:sizegray(2)
		if TCIgray(i,j) >200
			graycount=graycount+1;
		end
		
	end
end

graycount
pixelcount = sizegray(1)*sizegray(2)
if(graycount>0.4*pixelcount)
	cc = 2
	result_status2 = 'Too much cloud in cropped tci image'
	return
end
	
etci = etci(xstart:xend,ystart:yend,:);
ndvi = ndvi(xstart:xend,ystart:yend,:);
mndvi = mndvi(xstart:xend,ystart:yend,:);
imwrite(tci,filenametci);
imwrite(etci,filenameetci);
imwrite(ndvi,filenamendvi);
imwrite(mndvi,filenamemndvi);
%xstart = round(xstart/2)-1;
%xend = round(xend/2)-1;
%ystart = round(ystart/2)-1;
%yend = round(yend/2)-1;
ndwi = ndwi(xstart:xend,ystart:yend,:);
mndwi = mndwi(xstart:xend,ystart:yend,:);
ndre = ndre(xstart:xend,ystart:yend,:);
mndre = mndre(xstart:xend,ystart:yend,:);
imwrite(ndwi,filenamendwi);

imwrite(mndwi,filenamemndwi);
imwrite(ndre,filenamendre);

imwrite(mndre,filenamemndre);

cc = 1;
end
