% This is code for work published here: https://www.biorxiv.org/content/10.1101/2020.10.26.355560v1 % Three-dimensional biofilm growth supports a mutualism involving matrix and nutrient sharing % Heidi A. Arjes, Lisa Willis, Haiwen Gui, Yangbo Xiao, Jason Peters, Carol Gross, Kerwyn Casey Huang % doi: https://doi.org/10.1101/2020.10.26.355560 % This is a custom code designed by Heidi A. Arjes to quickly stitch grids % of images with a constant overlap into one image. It simply crops the % overlap and stitches the images % % stitch_images(images,M,rescale,overlap) % % images will contain all images that are to be stitched % M is the matrix of image numbers (so M(1,1) is the image number that will % be in the upper left, M(1,2) will be to the right of that, and so on). % % rescale is a rescaling factor (set to be 1 if you don't want to change % the image) % % overlap is the amount of overlap between images function Is = stitch_images(images,M,rescale,overlap) % nargin in the number of arguments provided if nargin<4 overlap = 0; end if nargin<3 rescale = 1; end % number of rows, columns in grid nc = size(M,2); nr = size(M,1); % define the grid for i=1:nr xshift(i,1:nc) = i-1; end for j=1:nc yshift(1:nr,j) = nc-j; end % figure; % subplot(1,2,1); % imagesc(xshift); colorbar % subplot(1,2,2); % imagesc(yshift);colorbar; % get the sizes of images n1 = size(images,1); % number of rows in each image n2 = size(images,2); % number of columns in each image %Is = zeros(nr*n1,nc*n2); % MAKE SURE THAT I HAVEN'T SWITCHED NR AND NC (NR=NC=3 FOR THIS EXAMPLE) for i=1:nr for j=1:nc I = images(:,:,M(i,j)); I2 = imresize(I,rescale); % get size of image nx = size(I2,2); ny = size(I2,1); % define overlap Xnpxov = round(nx*overlap/2); Ynpxov = round(ny*overlap/2); I3 = I2((Ynpxov+1):(ny-Ynpxov),(Xnpxov+1):(nx-Xnpxov)); %disp([Ynpxov+1 ny-Ynpxov Xnpxov+1 nx-Xnpxov]); % redefine the size of the images nx = size(I3,2); ny = size(I3,1); % define the part of the stitched image Is(yshift(i,j)*ny+1:yshift(i,j)*ny+ny,xshift(i,j)*nx+1:xshift(i,j)*nx+nx) = I3; %size(Is) %disp([yshift(i,j) xshift(i,j)]) %imshow(imadjust(Is)); end end