function [R, vertex, edge, edge_petal, N, grid_xy, centroids, REGS] = autoMakeGrid(reduce, reg_x, reg_y, max_regions, shape, thr, adjust_corners_flag)


[R, vertex, edge, edge_petal] = auto_regions(reduce,reg_x,reg_y,max_regions, double(shape));
region_inds = edge_petal(:,3);
[edge_petal, toind] = image_sort(edge_petal(:,1), edge_petal(:,2));
edge_petal = [edge_petal, region_inds(toind)];
[R, vertex, edge, edge_petal] = autoRemoveSmallRegions(R, vertex, edge, edge_petal, thr);
fprintf('Now finding the neighbours for each region...\n');
N = find_neighbours(R);
fprintf('done.\n');
grid_xy = calc_grid_outline(R);
centroids = get_centroids(R);
centroids = centroids(2:end, :);

edge_petal = make_edge_petal(REGS);