-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMergeStackMPTIFFA488.m
More file actions
54 lines (39 loc) · 1.28 KB
/
MergeStackMPTIFFA488.m
File metadata and controls
54 lines (39 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
function [ Ind ] = MergeStackMPTIFFA488( fname, first, last )
% This function reads the input TIF image stack 'fname', merge the first
% 'num' number of frames into a new single frame TIF file called 'fname_m.TIF'
% fname must be the full filename of a stack tiff image
sname = strcat(strtok(fname,'.'),'_m.TIF');
info = imfinfo(fname);
img_height = info(1,1).Height;
img_width = info(1,1).Width;
third = round(img_width/3);
% pre-allocate space for image stack
clear('imgstk', 'imgmrg');
imgstk = zeros(img_height, img_width, last-first+1, 'uint16');
imgmrg = zeros(img_height, round(img_width/3), 'uint16');
% load first few frames of the tiff stack, number of frames indicated by
% % num
% for k = 1:num
% imgstk(:,:,k) = imread(fname, k, 'Info', info);
%
% end
[imgstk,n] = imread(fname);
for k = first:last
imgstk(:,:,k+1-first) = imread(fname, k, 'Info', info);
end
% figure
% image(imgstk(:, :, 1),'CDataMapping','scaled')
% colormap(gray)
% create the merged image from the average of the image stack
for i = 1:img_height
for j = 2*third+1:img_width
imgmrg(i,j-2*third) = mean(imgstk(i,j,:)); %imgmrg(i,j) = mean(imgstk(i,j,:));
end
end
% plot the merged image
figure
imshow(imgmrg, [])%,'scaled')
colormap(gray)
imwrite(imgmrg, sname, 'tif');
Ind = j;
end