function draw_regions(regions,im_size,colour,lineWidth)
    regions(find(regions<0))=-regions(find(regions<0));

    hor_verticies=[0,0,0];%[ystart,xstart,xend]
    ver_verticies=[0,0,0];%[xstart,ystart,yend]
    
    
    for x=1:im_size(2)
        for y=1:im_size(1)-1
            if (regions(y,x)~=regions(y+1,x))
                index=1;
                while (index<=length(hor_verticies(:,1)))&&(hor_verticies(index,1)~=y+0.5 || hor_verticies(index,3)~=x-0.5)
                    index=index+1;
                end
                if index==length(hor_verticies(:,1))+1
                    hor_verticies=[hor_verticies;y+0.5,x-0.5,x+0.5];
                else
                    hor_verticies(index,3)=x+0.5;
                end
            end
        end
    end
    
    for y=1:im_size(1)
        for x=1:im_size(2)-1
            if (regions(y,x)~=regions(y,x+1))
                index=1;
                while (index<=length(ver_verticies(:,1)))&&(ver_verticies(index,1)~=x+0.5 || ver_verticies(index,3)~=y-0.5)
                    index=index+1;
                end
                if index==length(ver_verticies(:,1))+1
                    ver_verticies=[ver_verticies;x+0.5,y-0.5,y+0.5];
                else
                    ver_verticies(index,3)=y+0.5;
                end
            end
        end
    end
    
    for i=1:1:length(hor_verticies(:,1))
        plot([hor_verticies(i,2),hor_verticies(i,3)],[hor_verticies(i,1),hor_verticies(i,1)],colour,'LineWidth',lineWidth);
    end;
  
    for i=1:1:length(ver_verticies(:,1))
        plot([ver_verticies(i,1),ver_verticies(i,1)],[ver_verticies(i,2),ver_verticies(i,3)],colour,'LineWidth',lineWidth);
    end;