-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAutomaticSegmentation
More file actions
127 lines (110 loc) · 5.18 KB
/
AutomaticSegmentation
File metadata and controls
127 lines (110 loc) · 5.18 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
% Copyright (c) 2022 Olivier Rukundo
% Enhancing the Innovation Potential by Advancing the Know-How on Biomedical Image Analysis
% Kuopio Biomedical Image Analysis (KUBIAC)
% A.I. Virtanen Institute for Molecular Sciences, University of Eastern of Finland, Kuopio
% E-mail: olivier.rukundo@uef.fi | orukundo@gmail.com
% Version 1.0 dated 19.06.2022
classdef AutomaticSegmentation < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
AUTOMATICSEGMENTATIONOFMINITEMIMAGESUIFigure matlab.ui.Figure
SELECTIMAGEButton matlab.ui.control.Button
UIAxes matlab.ui.control.UIAxes
end
% Callbacks that handle component events
methods (Access = private)
% Button pushed function: SELECTIMAGEButton
function SELECTIMAGEButtonPushed(app, ~)
% Button button pushed function
[file,path] = uigetfile({'*.tif';'*.jpg';'*.bmp';'*.gif';'*.tiff'}, 'Select file');
if isequal(file,0)
disp('User selected Cancel');
else
T1 = fullfile(path,file);
FT1 = dir(T1);
selected_file = fullfile(FT1.folder, FT1.name);
input_image = imread(selected_file);
input_image_uint16 = uint16(input_image);
%Loading image
f = waitbar(0,'Please wait...');
pause(.5)
waitbar(.33,f,'Loading your image');
pause(1)
% Automatic segmentation
warning('off');
ld = load('unet_VALL');
netld = ld.net;
% Processing image
waitbar(.67,f,'Processing your image');
pause(1)
segmented_image = semanticseg(input_image_uint16, netld);
segmented_image_double = mat2gray(uint8(segmented_image));
% Print outline of segmented image
segmented_image_uint16 = uint16(255 * segmented_image_double);
outlined_image_new = PrintOutlineOfMask(input_image_uint16, segmented_image_uint16);
end
% Display image
waitbar(1,f,'Finishing');
pause(1)
close(f)
imshow(outlined_image_new, 'parent', app.UIAxes);
end
end
% Component initialization
methods (Access = private)
% Create UIFigure and components
function createComponents(app)
% Create AUTOMATICSEGMENTATIONOFMINITEMIMAGESUIFigure and hide until all components are created
app.AUTOMATICSEGMENTATIONOFMINITEMIMAGESUIFigure = uifigure('Visible', 'off');
app.AUTOMATICSEGMENTATIONOFMINITEMIMAGESUIFigure.Color = [0.502 0.502 0.502];
app.AUTOMATICSEGMENTATIONOFMINITEMIMAGESUIFigure.Position = [100 100 1342 903];
app.AUTOMATICSEGMENTATIONOFMINITEMIMAGESUIFigure.Name = 'AUTOMATIC SEGMENTATION OF MINITEM IMAGES';
app.AUTOMATICSEGMENTATIONOFMINITEMIMAGESUIFigure.Icon = 'icon.jpg';
app.AUTOMATICSEGMENTATIONOFMINITEMIMAGESUIFigure.WindowState = 'maximized';
% Create UIAxes
app.UIAxes = uiaxes(app.AUTOMATICSEGMENTATIONOFMINITEMIMAGESUIFigure);
title(app.UIAxes, {''; ''; ''; ''; ''; '-'})
app.UIAxes.AmbientLightColor = 'none';
app.UIAxes.XTick = [];
app.UIAxes.YTick = [];
app.UIAxes.BoxStyle = 'full';
app.UIAxes.LineWidth = 1.5;
app.UIAxes.Color = [0.302 0.7451 0.9333];
app.UIAxes.FontSize = 8;
app.UIAxes.TitleFontWeight = 'normal';
app.UIAxes.Clipping = 'off';
app.UIAxes.Box = 'on';
app.UIAxes.Position = [352 41 860 847];
% Create SELECTIMAGEButton
app.SELECTIMAGEButton = uibutton(app.AUTOMATICSEGMENTATIONOFMINITEMIMAGESUIFigure, 'push');
app.SELECTIMAGEButton.ButtonPushedFcn = createCallbackFcn(app, @SELECTIMAGEButtonPushed, true);
app.SELECTIMAGEButton.IconAlignment = 'center';
app.SELECTIMAGEButton.BackgroundColor = [0.149 0.149 0.149];
app.SELECTIMAGEButton.FontSize = 20;
app.SELECTIMAGEButton.FontWeight = 'bold';
app.SELECTIMAGEButton.FontColor = [0.902 0.902 0.902];
app.SELECTIMAGEButton.Position = [151 184 202 75];
app.SELECTIMAGEButton.Text = 'SELECT IMAGE';
% Show the figure after all components are created
app.AUTOMATICSEGMENTATIONOFMINITEMIMAGESUIFigure.Visible = 'on';
end
end
% App creation and deletion
methods (Access = public)
% Construct app
function app = AutomaticSegmentation
% Create UIFigure and components
createComponents(app)
% Register the app with App Designer
registerApp(app, app.AUTOMATICSEGMENTATIONOFMINITEMIMAGESUIFigure)
if nargout == 0
clear app
end
end
% Code that executes before app deletion
function delete(app)
% Delete UIFigure when app is deleted
delete(app.AUTOMATICSEGMENTATIONOFMINITEMIMAGESUIFigure)
end
end
end