forked from ElliotPadgett/PC-STEM
-
Notifications
You must be signed in to change notification settings - Fork 4
/
bblank.m
49 lines (43 loc) · 1.46 KB
/
bblank.m
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
function [ im ] = bblank( im, bsize, shape, center, val )
%bblank adds "beam blank" to image im
% input:
% im -- 2d image to add blanked region to
% bsize -- blank spot radius or edge half-length in pixels (default 2)
% shape -- square 's' or circle 'c' (optional, default 's')
% val -- value to fill in blanked region (optional, default 0)
% output:
% blankedim -- image with beam blank added
%
%This function is part of the PC-STEM Package by Elliot Padgett in the
%Muller Group at Cornell University. Last updated June 26, 2019.
%default values
switch nargin
case 4
val = 0;
case 3
val = 0; center = 0.5*(size(im)+1);
case 2
val = 0; center = 0.5*(size(im)+1); shape = 's';
case 1
val = 0; center = 0.5*(size(im)+1); shape = 's'; bsize = 2;
end
Nd=ndims(im);
switch shape
case 's'
if Nd==2
im(round(center(1)-bsize):round(center(1)+bsize),...
round(center(2)-bsize):round(center(2)+bsize)) = val;
elseif Nd==4
im(round(center(1)-bsize):round(center(1)+bsize),...
round(center(2)-bsize):round(center(2)+bsize),:,:) = val;
end
case 'c'
[N1,N2,N3,N4] = size(im);
[X,Y] = meshgrid(1:N1,1:N2);
blank = repmat((X-center(1)).^2 + (Y-center(2)).^2 <= bsize^2,1,1,N3,N4);
im = im .* single(~blank);
im = im + val*blank;
otherwise
error('bblank: Unrecognized shape')
end
end