clear all; close all; clc

% umelo vytvorený obraz pre segmentáciu z obrazov brodatz

% výber obrazov z databázy

% br_1 = double(imread('D4.gif'));
% br_2 = double(imread('D16.gif'));
% br_3 = double(imread('D19.gif'));
% br_4 = double(imread('D29.gif'));
% br_5 = double(imread('D53.gif'));

br_1 = double(imread('D77.gif'));
br_2 = double(imread('D16.gif'));
br_3 = double(imread('D4.gif'));
br_4 = double(imread('D29.gif'));
br_5 = double(imread('D53.gif'));

% br_1 = double(imread('D4.gif'));
% br_2 = double(imread('D77.gif'));
% br_3 = double(imread('D16.gif'));
% br_4 = double(imread('D24.gif'));
% br_5 = double(imread('D53.gif'));

s1 = ones(256, 256)*1;
s2 = ones(256, 256)*2;
s3 = ones(256, 256)*3;
s4 = ones(256, 256)*4;
s5 = ones(512, 512)*5;

br_1 = br_1(1:256, 1:256);
br_2 = br_2(1:256, 1:256);
br_3 = br_3(1:256, 1:256);
br_4 = br_4(1:256, 1:256);
br_5 = br_5(1:512, 1:512);

podklad = zeros(512, 512);
podklad(1:256, 1:256) = br_1;
podklad(1:256, 257:512) = br_2;
podklad(257:512, 1:256) = br_3;
podklad(257:512, 257:512) = br_4;

podklad1 = zeros(512, 512);
podklad1(1:256, 1:256) = s1;
podklad1(1:256, 257:512) = s2;
podklad1(257:512, 1:256) = s3;
podklad1(257:512, 257:512) = s4;



kruh = br_5;
kruh1 = s5;

c = [255, 255]; % súradnice stredu
r = 120; % polomer kruhu
mask = bsxfun(@plus, ((1:512) - c(1)).^2, (transpose(1:512) - c(2)).^2) < r^2;

% inverzná maska
i_m = ones(512);
i_mask = abs(i_m-mask);

a = kruh.*mask;
b = podklad.*i_mask;
c = a+b;

a1 = kruh1.*mask;
b1 = podklad1.*i_mask;
c1 = a1+b1;

figure
imshow(c, [])

figure
imshow(c1, [])

obraz = c;
segmenty = c1;
% save('obr_na_segmentaciu_br.mat','obraz', 'segmenty')
save('obr_na_segmentaciu_br2.mat','obraz', 'segmenty')
% save('obr_na_segmentaciu_br3.mat','obraz', 'segmenty')
% save('obr_na_segmentaciu_br4.mat','obraz', 'segmenty')
