function [T2,N] = CA_A4(T1,white, black) 
%CA A4 boji dio backbone-a u rezerviranu boju (zelenu) (ne boji jedino bijele celije)
%CA_A4 colors remaining tagged articulation cells, which are part of backbone with backbone color

T2=T1;
N=0;
global cmap;
global Plot;

tagColor1 = length(cmap)-4;
tagColor2 = length(cmap)-5;
tagColor3 = length(cmap)-6;
tagColor4 = length(cmap)-7;
tagColor5 = length(cmap)-8;
tagColor6 = length(cmap)-9;
tagColor7 = length(cmap)-10;
tagColor8 = length(cmap)-11;
tagColor9 = length(cmap)-12;
tagColor10 = length(cmap)-13;
tagColor11 = length(cmap)-14;
tagColor12 = length(cmap)-15;

green = length(cmap);

 for i=1:10000
for lines=3:size(T1,1)-1
    for columns=2:size(T1,2)-1
% %             stopUnutrasnjeRupe = false;
            if (T1(lines, columns) ==  white || T1(lines, columns) == black || (T1(lines, columns) >= tagColor12 && T1(lines, columns) <= tagColor1))% black || tagged cells
                if (lines == 3 || lines == size(T1,1)-2) %on upper || lower edge
%tako je bilo prej - napaka!               if (lines == 1 || lines == size(T1,1)-1) %on upper || lower edge
                    T2(lines, columns)= green; 
                elseif (T1(lines, columns) == black && (T1(lines-1, columns) == green || T1(lines+1, columns) == green || T1(lines, columns-1) == green || T1(lines, columns+1) == green))
                    T2(lines, columns)= green;
                elseif (T1(lines, columns) ~= white)
                    if(T1(lines-1,columns) == white && T1(lines+1,columns) == white && ((T1(lines-1,columns-1) == green && T1(lines+1,columns-1) == green ) || ...
                         (T1(lines-1,columns+1) == green && T1(lines+1,columns+1) == green ) || (T1(lines-1,columns-1) == green && T1(lines+1,columns+1) == green ) || ... 
                         (T1(lines-1,columns+1) == green && T1(lines+1,columns+1) == green )))   
                        T2(lines, columns)= green; 
                    elseif(T1(lines,columns+1) == white && T1(lines,columns-1) == white && ((T1(lines-1,columns-1) == green && T1(lines+1,columns-1) == green ) || ...
                          (T1(lines-1,columns+1) == green && T1(lines+1,columns+1) == green ) || (T1(lines-1,columns-1) == green && T1(lines+1,columns+1) == green ) || ...
                          (T1(lines-1,columns+1) == green && T1(lines+1,columns+1) == green )))  
                        T2(lines, columns)= green; 
                    elseif((T1(lines,columns-1) == green || T1(lines+1,columns) == green || T1(lines-1,columns) == green || T1(lines,columns+1) == green) && ...
                          (columns ~= 1 && columns ~= size(T1,2)-1))  
                        T2(lines, columns)= green; 
                    elseif(T1(lines-1,columns) == white && ((T1(lines-1,columns-1) == green && T1(lines-1,columns+1) ~= T1(lines,columns)) || ...
                          (T1(lines-1,columns-1) ~= T1(lines,columns) && T1(lines-1,columns+1) == green)))   
                        T2(lines, columns)= green; 
                    elseif(T1(lines,columns-1) == white && ((T1(lines-1,columns-1) == green && T1(lines+1,columns-1) ~= T1(lines,columns)) || ...
                          (T1(lines+1,columns-1) ~= T1(lines,columns) && T1(lines-1,columns-1) == green)))   
                        T2(lines, columns)= green; 
                    elseif(T1(lines+1,columns) == white && ((T1(lines+1,columns-1) == green && T1(lines+1,columns+1) ~= T1(lines,columns)) || ...
                          (T1(lines+1,columns-1) ~= T1(lines,columns) && T1(lines+1,columns+1) == green)))   
                        T2(lines, columns)= green; 
                    elseif(T1(lines,columns+1) == white && ((T1(lines-1,columns+1) == green && T1(lines+1,columns+1) ~= T1(lines,columns)) || ...
                          (T1(lines-1,columns+1) ~= T1(lines,columns) && T1(lines+1,columns+1) == green)))    
                        T2(lines, columns)= green;                    
                    end
                end
            end
            N=N+1;
        end
    end
    if (norm(T1)==norm(T2))
        %         %%ADES
        T2(2,3:size(T2,2)-2)=black;
        T2(size(T2,1)-1,3:size(T2,2)-2)=black;
%         %end ADES
        return; 
    else
        T1=T2;
%    if (Plot)       figure; colormap(cmap); image((T2((2:size(T2,1)-1),(2:size(T2,2)-1)))); title('CA\_A4'); colorbar;  set(gcf,'renderer','OpenGL');end
    end
 end
