-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFilterImages.m
More file actions
57 lines (46 loc) · 1.84 KB
/
FilterImages.m
File metadata and controls
57 lines (46 loc) · 1.84 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
52
53
54
55
56
57
%Filter the images using Gaussian filter (size: Hsize, sigma:
%GaussianSigma)
%
%FileName: a name of the .tiff file from scanimage.
%Hsize: size of a gaussian filter (Matlab standard). Recommended value 5:
%may be 3?
%GaussianSigma: standard deviation of the Gaussian distribution.
%Recommended value 3, may be 0.5?
%NofChannels: Number of channels in the recording.
%
%LowI: Low range for image display.
%HighI: High range for image display.
%
function []=FilterImages(FileName,Hsize,GaussianSigma,NofChannels,LowI,HighI)
%Get the image information.
ImageInfo=imfinfo(FileName);
%Check the number of images in a file.
FrameN=length(ImageInfo);
%Get row (Height) and column (Width) number from the structure InfoSize
SizeOfImage(1)=ImageInfo(1).Height;
SizeOfImage(2)=ImageInfo(1).Width;
%Initialize the matrix for the entire image.
ImageData=int16(zeros(SizeOfImage(1),SizeOfImage(2),FrameN));
%Code to read TIFF using TIFF library.
FileLink = Tiff(FileName,'r');
for n=1:FrameN
FileLink.setDirectory(n);
ImageData(:,:,n)=FileLink.read();
end
FileLink.close();
%Find frames per channel.
FrameN=FrameN/NofChannels;
%Initialize the matrix
FilteredImages=int16(zeros(SizeOfImage(1),SizeOfImage(2),NofChannels,FrameN));
figure;%Make new figure
for frame=1:FrameN
%Filter the image using gaussian filter.
FilteredImages(:,:,:,frame)=imgaussfilt(ImageData(:,:,(frame-1)*NofChannels+1:frame*NofChannels),GaussianSigma,'FilterSize',Hsize);
%Display the image for the SignalChannel.
imshow(FilteredImages(:,:,SignalChannel,frame),[LowI,HighI]);
end
position=strfind(FileName,'.'); %gives the position of the period in the string FileName
NewName=FileName(1:position-1); %string NewName has the file name without the ".tiff".
Outfile = strcat(NewName,'FilterImages');
save(Outfile,'FilteredImages');
clear