-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfrmProcess.vb
267 lines (217 loc) · 10.8 KB
/
frmProcess.vb
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
Option Explicit On
Option Strict On
Public Class frmProcess
Private Sub frmProcess_Load(sender As Object, e As EventArgs) Handles Me.Load
'List all channels
With cbChannels
'Add all entries
.Items.Clear()
For Each Entry As String In DB.Channels.Keys
.Items.Add(Entry & " (" & DB.Channels(Entry).SourceFileName & ")")
Next Entry
'Select last entry
If .Items.Count > 0 Then .SelectedIndex = .Items.Count - 1
End With
'Tooltop on file
ttMain.SetToolTip(cbChannels, CStr(cbChannels.SelectedItem))
'Reset all action dropdown's
cbRescale.SelectedIndex = 0
cbPowers.SelectedIndex = 0
cbFlipRotate.SelectedIndex = 0
cbComplexOperations.SelectedIndex = 0
End Sub
'''<summary>BEFORE processing, get the channel that is processed.</summary>
Private Function DisplayedChannel() As String
If cbChannels.SelectedIndex <> -1 Then
tsslStatus.Text = "Processing channel " & cbChannels.SelectedItem.ToString.Trim & " ..."
System.Windows.Forms.Application.DoEvents()
Dim SelectedChannel As String = CStr(cbChannels.SelectedItem)
If String.IsNullOrEmpty(SelectedChannel) = True Then
Return String.Empty
Else
Return SelectedChannel.Substring(0, SelectedChannel.IndexOf("(") - 1).Trim
End If
Else
Return String.Empty
End If
End Function
'''<summary>AFTER processing, update all forms that display the channel.</summary>
Private Sub UpdateFormsDisplayingChannel(ByVal UpdateStatistics As Boolean)
Dim openForms As Windows.Forms.FormCollection = Application.OpenForms
For Each frm As Windows.Forms.Form In openForms
If frm.GetType.Name = "frmImage" Then
With CType(frm, frmImage)
If .DisplayedChannel = DisplayedChannel() Then
If UpdateStatistics Then DB.Channels(.DisplayedChannel).CalculateStatistics()
.UpdateImage()
End If
End With
End If
Next frm
tsslStatus.Text = "IDLE"
System.Windows.Forms.Application.DoEvents()
End Sub
Private Sub cbRescale_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cbRescale.SelectedIndexChanged
Dim ChannelToEdit As String = DisplayedChannel() : If String.IsNullOrEmpty(ChannelToEdit) = True Then Exit Sub
Select Case cbRescale.SelectedIndex
Case 0
'Do nothing
Exit Sub
Case 1
'Modify the channel
DB.Channels(ChannelToEdit).Expand(0, 255)
Case 2
'Modify the channel
DB.Channels(ChannelToEdit).Expand(0, 65535)
Case 3
'Modify the channel
DB.Channels(ChannelToEdit).Expand(0, 1)
Case 4
'User
Dim Min As Double = Val(InputBox("Minimum:", "Minimum", "0").Replace(",", "."))
Dim Max As Double = Val(InputBox("Maximum:", "Maximum", "255").Replace(",", "."))
DB.Channels(ChannelToEdit).Expand(Min, Max)
End Select
'Update all form that display the channel
UpdateFormsDisplayingChannel(True)
cbRescale.SelectedIndex = 0
End Sub
Private Sub cbPowers_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cbPowers.SelectedIndexChanged
Dim ChannelToEdit As String = DisplayedChannel() : If String.IsNullOrEmpty(ChannelToEdit) = True Then Exit Sub
Select Case cbPowers.SelectedIndex
Case 0
'Do nothing
Exit Sub
Case 1
'^2
'Modify the channel
DB.IPP.Sqr(DB.Channels(ChannelToEdit).ImageData)
Case 2
'^3
'Modify the channel
Dim Copy As Double(,) = DB.IPP.Copy(DB.Channels(ChannelToEdit).ImageData)
DB.IPP.Mul(DB.Channels(ChannelToEdit).ImageData, Copy)
DB.IPP.Mul(Copy, DB.Channels(ChannelToEdit).ImageData)
Case 3
'sqrt(...)
DB.IPP.Sqrt(DB.Channels(ChannelToEdit).ImageData)
End Select
'Update all form that display the channel
UpdateFormsDisplayingChannel(True)
cbPowers.SelectedIndex = 0
End Sub
Private Sub cbFlipRotate_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cbFlipRotate.SelectedIndexChanged
Dim ChannelToEdit As String = DisplayedChannel() : If String.IsNullOrEmpty(ChannelToEdit) = True Then Exit Sub
Select Case cbFlipRotate.SelectedIndex
Case 0
'Do nothing
Exit Sub
Case 1
'Flip left-right
DB.Channels(ChannelToEdit).FlipLR()
Case 2
'Flip top-buttom
DB.Channels(ChannelToEdit).FlipTB()
Case 3
'Rotate clockwise
DB.Channels(ChannelToEdit).RotateCW()
Case 4
'Rotate counter-clock wise
DB.Channels(ChannelToEdit).RotateCCW()
End Select
'Update all form that display the channel
UpdateFormsDisplayingChannel(False)
cbFlipRotate.SelectedIndex = 0
End Sub
Private Sub cbChannels_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cbChannels.SelectedIndexChanged
'Tooltop on file
ttMain.SetToolTip(cbChannels, CStr(cbChannels.SelectedItem))
End Sub
Private Sub cbComplexOperations_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cbComplexOperations.SelectedIndexChanged
Dim ChannelToEdit As String = DisplayedChannel() : If String.IsNullOrEmpty(ChannelToEdit) = True Then Exit Sub
Select Case cbComplexOperations.SelectedIndex
Case 0
'Do nothing
Exit Sub
Case 1
'Invert within given range
DB.Channels(ChannelToEdit).Invert()
Case 2
'Sin
DB.Channels(ChannelToEdit).Expand(0, 1)
DB.IPP.Sin(DB.Channels(ChannelToEdit).ImageData)
Case 3
'Experimental - smear the complete intensity range over the complete range (0...255) currently
' After that, each pixel has a different intensity and the historgram is a straight horizontal line
'Moved to ImageProcessing.vb
Case 4
'Push low and high intensity
Dim SplitPercentage As Double = 5
Dim Multiplier As Double = 5
Dim Min As Double
Dim Max As Double
DB.IPP.MinMax(DB.Channels(ChannelToEdit).ImageData, Min, Max)
MathEx.MaxMinIgnoreNAN(DB.Channels(ChannelToEdit).ImageData, Min, Max)
Dim Below As Double = Min + ((SplitPercentage / 100) * (Max - Min))
Dim Above As Double = Min + (((100 - SplitPercentage) / 100) * (Max - Min))
For Idx1 As Integer = 0 To DB.Channels(ChannelToEdit).ImageData.GetUpperBound(0)
For Idx2 As Integer = 0 To DB.Channels(ChannelToEdit).ImageData.GetUpperBound(1)
Dim CurrentIntensity As Double = DB.Channels(ChannelToEdit).ImageData(Idx1, Idx2)
If CurrentIntensity <= Below Then
CurrentIntensity *= Multiplier
Else
If CurrentIntensity >= Above Then
CurrentIntensity = Max - CurrentIntensity
CurrentIntensity *= Multiplier
CurrentIntensity = Max - CurrentIntensity
End If
End If
DB.Channels(ChannelToEdit).ImageData(Idx1, Idx2) = CurrentIntensity
Next Idx2
Next Idx1
Case 5
'Remove stars
Dim StarsToRemove As Integer = 10
StarRemover.RemoveStars(DB.Channels(ChannelToEdit).ImageData, StarsToRemove)
Case 6
'Remove highest amplitude(s)
Dim Min As Double
Dim Max As Double
Dim Range As Double = Val(InputBox("Range:", "Range", "10").Replace(",", "."))
DB.IPP.MinMax(DB.Channels(ChannelToEdit).ImageData, Min, Max)
For Idx1 As Integer = 0 To DB.Channels(ChannelToEdit).ImageData.GetUpperBound(0)
For Idx2 As Integer = 0 To DB.Channels(ChannelToEdit).ImageData.GetUpperBound(1)
Dim CurrentIntensity As Double = DB.Channels(ChannelToEdit).ImageData(Idx1, Idx2)
If CurrentIntensity >= Max - Range Then
CurrentIntensity = Min
End If
DB.Channels(ChannelToEdit).ImageData(Idx1, Idx2) = CurrentIntensity
Next Idx2
Next Idx1
Case 7
Dim Min As Double
Dim Max As Double
DB.IPP.MinMax(DB.Channels(ChannelToEdit).ImageData, Min, Max)
'Calculate center-of-object
Dim CenterOfMass As PointF = ImageAnalysis.CenterOfMass(DB.Channels(ChannelToEdit))
For Radius As Double = 50 To 1000 Step 50
For Angle As Double = 0 To 2 * Math.PI Step Math.PI / 3600
Dim X As Double = CenterOfMass.X + (Radius * Math.Sin(Angle))
Dim Y As Double = CenterOfMass.Y + (Radius * Math.Cos(Angle))
DB.Channels(ChannelToEdit).ImageData(CInt(X), CInt(Y)) = Min
Next Angle
Next Radius
Case 8
'Grid bright start
InImplementation.GridBrightStars(ChannelToEdit, 16, 1, "C:\GridOut.bmp")
End Select
'Update all form that display the channel
UpdateFormsDisplayingChannel(True)
cbComplexOperations.SelectedIndex = 0
End Sub
Private Sub btnHisto_Click(sender As Object, e As EventArgs) Handles btnHisto.Click
Dim Hist As New frmHistogram
Hist.Show()
Hist.LoadData(DB.Channels(DisplayedChannel).HistCalc.Histogram, DB.Channels(DisplayedChannel).HistCalc.Minimum, DB.Channels(DisplayedChannel).HistCalc.Maximum)
End Sub
End Class