
imageRGBUncut = imread('book+2.jpeg', 'jpeg');
imageUncut = rgb2gray(imageRGBUncut);
image = imageUncut(1:480, 1:624);

% code to devide image into 4x4 segments
% recall : image size: 480 x 624
%          segment size : 120 x 156
%          window size : 20 x 26


segment1 = image(1:120, 1:156);
segment2 = image(1:120, 157:312);
segment3 = image(1:120, 313:468);
segment4 = image(1:120, 469:624);
segment5 = image(121:240, 1:156);
segment6 = image(121:240, 157:312);
segment7 = image(121:240, 313:468);
segment8 = image(121:240, 469:624);
segment9 = image(241:360, 1:156);
segment10 = image(241:360, 157:312);
segment11 = image(241:360, 313:468);
segment12 = image(241:360, 469:624);
segment13 = image(361:480, 1:156);
segment14 = image(361:480, 157:312);
segment15 = image(361:480, 313:468);
segment16 = image(361:480, 469:624);

% find segment stats for eacg segment
% segmentAnalysis returns in the order [Contrast, Focus, Texture]

[c1, f1, t1] = segmentAnalysis(segment1);
[c2, f2, t2] = segmentAnalysis(segment2);
[c3, f3, t3] = segmentAnalysis(segment3);
[c4, f4, t4] = segmentAnalysis(segment4);
[c5, f5, t5] = segmentAnalysis(segment5);
[c6, f6, t6] = segmentAnalysis(segment6);
[c7, f7, t7] = segmentAnalysis(segment7);
[c8, f8, t8] = segmentAnalysis(segment8);
[c9, f9, t9] = segmentAnalysis(segment9);
[c10, f10, t10] = segmentAnalysis(segment10);
[c11, f11, t11] = segmentAnalysis(segment11);
[c12, f12, t12] = segmentAnalysis(segment12);
[c13, f13, t13] = segmentAnalysis(segment13);
[c14, f14, t14] = segmentAnalysis(segment14);
[c15, f15, t15] = segmentAnalysis(segment15);
[c16, f16, t16] = segmentAnalysis(segment16);

c = [c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11 c12 c13 c14 c15 c16];
f = [f1 f2 f3 f4 f5 f6 f7 f8 f9 f10 f11 f12 f13 f14 f15 f16];
t = [t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16];

% normalize matrices so that their range is between 0 and 1
c = c/max(c);
f = f/max(f);
t = t/max(t);
	  

% calculate visual significance of each segment using
%  V(s) = F(s) [alphaC +(1-alpha)T]
% choose alpha between 0 an 1, typically 0.5-0.75

alpha = 0.7
visualSig = f .* (alpha*c + (1-alpha) * t)

% choose a threshold VT  typically 0.4 to 0.7
% if V(S) > VT then the segment is visually significant
% find the average intensity in each of the visual segments


pAvg1 = sum(sum(segment1))/(120 * 156);
pAvg4 = sum(sum(segment4))/(120 * 156);
pAvg5 = sum(sum(segment5))/(120 * 156);
pAvg8 = sum(sum(segment8))/(120 * 156);
pAvg9 = sum(sum(segment9))/(120 * 156);
pAvg11 = sum(sum(segment11))/(120 * 156);
pAvg13 = sum(sum(segment13))/(120 * 156);
pAvg15 = sum(sum(segment15))/(120 * 156);
pAvg16 = sum(sum(segment16))/(120 * 156);

gradient = getGradient;

pAvg = (pAvg1 + pAvg4+ pAvg5+pAvg8+pAvg9+pAvg11+pAvg13+pAvg15+pAvg16)/9;
dx = stops(pAvg, 128, gradient);

for i=1:480,
  for j=1:624,
    image(i, j) = push(double(image(i,j)), dx, gradient);
end
end

% visually important segment 1, 4, 5, 8, 9,  11, 13, 15, 16 = 165.5953



sfdqwqwe1 214













