-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathimageBC.m
59 lines (47 loc) · 1.9 KB
/
imageBC.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
49
50
51
52
53
54
55
56
57
58
59
function imageBC(im)
% Brightness & Contrast enabled imagesc
% by Suk Hyun Sung @ hovdenlab
% Create new figure and perform imagesc,
% return figure, imagesc handle
f = figure;
h = imagesc(im);
colormap(parula(65535))
% Find default min, max
cmin = min(im(:));
cmax = max(im(:));
% Add sliders
sl1 = uicontrol('style','slider','position',[10 60 20 300],'min', cmin, 'max', cmax,'Value', cmin);
sl2 = uicontrol('style','slider','position',[35 60 20 300],'min', cmin, 'max', cmax,'Value', cmax);
% filename box
txtbox = uicontrol('style','edit','position',[50 5 80 20],'String','File Name');
% Add button
btApply = uicontrol('style','pushbutton','position',[10 5 30 20],'String','Apply','CallBack', @(hObject,eventdata) appliedIm(im,get(sl1,'Value'),get(sl2,'Value')));
btSave = uicontrol('style','pushbutton','position',[140 5 30 20],'String','Save','CallBack', @(hObject,eventdata) saveIm(im,sl1,sl2,txtbox));
% Listen to slider values and change B & C
addlistener(sl1, 'Value', 'PostSet',@(hObject,eventdata) setCaxis(sl1,sl2));
addlistener(sl2, 'Value', 'PostSet',@(hObject,eventdata) setCaxis(sl1,sl2));
end
function appliedIm(im,cmin,cmax)
figure
imagesc(im,[cmin, cmax])
im_thr = im;
im_thr( im_thr > cmax ) = cmax;
im_thr( im_thr < cmin ) = cmin;
assignin('base','im_thr',im_thr)
end
function saveIm(im,sl1,sl2,txtbox)
cmin = get(sl1,'Value');
cmax = get(sl2,'Value');
im( im<cmin ) = cmin;
im( im>cmax ) = cmax;
im = im - cmin;
im = uint16(65535 * im / max(im(:)));
imwrite(im, [txtbox.String,'.tif'])
end
function setCaxis(sl1,sl2)
cmin = get(sl1,'Value');
cmax = get(sl2,'Value');
caxis([cmin, cmax]);
title(sprintf('min = %f, max = %f', cmin, cmax));
end