bayered = imread("/Users/natalie/mm data/RED/RED_F4.0_25ms/141417.tiff");
mask = "rggb";

debayered = demosaic(bayered, mask);

[r, g, b] = imsplit(debayered);

final = zeros(3040, 4064);

for j = 1:2:4064
    for i = 1:2:3040
        final(i, j) = r(i, j);
    end
end

for j = 2:2:4064
    for i = 1:2:3040
        final(i, j) = g(i, j);
    end
end 

for j = 1:2:4064
    for i = 2:2:3040
        final(i, j) = g(i, j);
    end
end 

for j = 2:2:4064
    for i = 2:2:3040
        final(i, j) = b(i, j);
    end
end 
final = cast(final, 'uint16');