-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp3.html
More file actions
377 lines (329 loc) · 21.8 KB
/
p3.html
File metadata and controls
377 lines (329 loc) · 21.8 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
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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Practical 3: Negation, Subtraction & Inversion | CSU2543</title>
<meta name="description" content="Digital Image Processing Practical 3 - Image Negation, Subtraction and Inversion. CSU2543, Shoolini University.">
<meta name="author" content="Divya Mohan">
<script>
(function(){var t=localStorage.getItem('dip-theme');if(!t){t=window.matchMedia&&window.matchMedia('(prefers-color-scheme:dark)').matches?'dark':'light';}document.documentElement.setAttribute('data-theme',t);})();
</script>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
<link rel="stylesheet" href="./css/base.css">
<link rel="stylesheet" href="./css/components.css">
<style>
.print-only { display: none; }
@media print {
* { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; }
@page { margin: 0.75in 0.85in 0.75in 0.85in; }
body {
background: white !important; color: black !important;
font-family: 'Times New Roman', Times, serif !important;
font-size: 12pt !important; line-height: 1.45 !important; margin: 0 !important;
}
.dip-navbar, .theme-toggle, .skip-link, #toast, .btn-run,
.image-select, .chapter-select, select, .btn-pair, .pair-btn,
input[type="range"], .slider-group, .no-print, .site-footer,
.card-arrow, .hero-badge, .hero, .practical-grid,
.picker-bar, .image-picker, .picker-label,
label[for], input[type="radio"], .colab-badge { display: none !important; }
.print-only { display: block !important; }
.print-cover {
display: flex !important; flex-direction: column; align-items: center; justify-content: center;
min-height: 100vh; page-break-after: always; text-align: center;
padding: 0.75in 1in; font-family: 'Times New Roman', Times, serif !important; border: 3pt double black; margin: 0;
}
.print-cover .cover-logo { width: 140px; height: auto; margin-bottom: 18pt; }
.print-cover .cover-university { font-size: 20pt; font-weight: bold; text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 4pt; }
.print-cover .cover-dept { font-size: 12pt; margin-bottom: 28pt; color: #222; line-height: 1.6; }
.print-cover .cover-rule { width: 60%; height: 2pt; background: black; margin: 0 auto 20pt; }
.print-cover .cover-subject { font-size: 18pt; font-weight: bold; margin-bottom: 4pt; letter-spacing: 0.03em; }
.print-cover .cover-code { font-size: 13pt; font-weight: bold; margin-bottom: 20pt; color: #333; }
.print-cover .cover-practical { font-size: 15pt; font-weight: bold; font-style: italic; margin-bottom: 32pt; padding: 8pt 24pt; border-top: 1pt solid #666; border-bottom: 1pt solid #666; }
.print-cover .cover-table { border-collapse: collapse; font-size: 12pt; margin: 0 auto; text-align: left; }
.print-cover .cover-table td { padding: 4pt 12pt; vertical-align: top; }
.print-cover .cover-table td:first-child { font-weight: bold; text-align: right; padding-right: 16pt; white-space: nowrap; }
.print-cover .cover-rule-sm { width: 25%; height: 0.75pt; background: #888; margin: 28pt auto 10pt; }
.print-cover .cover-session { font-size: 12pt; font-style: italic; color: #444; }
.container { max-width: 100% !important; padding: 0 !important; }
#main-content { padding: 0 !important; margin: 0 !important; }
h2, #main-content h2 { font-family: 'Times New Roman', Times, serif !important; font-size: 16pt !important; font-weight: bold !important; text-align: center !important; margin: 14pt 0 10pt !important; padding: 0 !important; border: none !important; display: block !important; color: black !important; }
h3, .section-card h3 { font-family: 'Times New Roman', Times, serif !important; font-size: 13pt !important; font-weight: bold !important; color: black !important; border: none !important; border-bottom: 0.5pt solid #ccc !important; padding: 0 0 3pt 0 !important; margin: 10pt 0 6pt !important; }
h4, .analysis-box h4 { font-family: 'Times New Roman', Times, serif !important; font-size: 12pt !important; font-weight: bold !important; font-style: italic !important; color: black !important; margin: 8pt 0 4pt !important; padding: 0 !important; }
.section-card { background: transparent !important; border: none !important; box-shadow: none !important; padding: 0 !important; margin-bottom: 6pt !important; }
.section-card p, p { font-size: 12pt !important; text-align: justify !important; max-width: none !important; margin-bottom: 4pt !important; line-height: 1.45 !important; }
.theory-box { background: #f7f7f7 !important; border-left: 2.5pt solid #333 !important; border-top: none !important; border-right: none !important; border-bottom: none !important; padding: 6pt 10pt !important; margin: 6pt 0 !important; font-size: 11pt !important; color: black !important; page-break-inside: avoid; }
.formula-box { display: block !important; text-align: center !important; font-size: 13pt !important; padding: 6pt !important; background: transparent !important; border: none !important; margin: 4pt 0 !important; }
.analysis-box { background: transparent !important; border-top: 1pt solid #ccc !important; border-bottom: none !important; border-left: none !important; border-right: none !important; padding: 6pt 0 0 !important; margin: 10pt 0 !important; page-break-inside: avoid; }
.analysis-box ol { font-size: 11pt !important; padding-left: 18pt !important; }
.analysis-box li { margin-bottom: 3pt !important; text-align: justify !important; line-height: 1.45 !important; }
.result-img { max-width: 95% !important; max-height: 8.5in !important; width: auto !important; height: auto !important; margin: 6pt auto !important; display: block !important; border: 0.5pt solid #bbb !important; border-radius: 0 !important; }
img { max-width: 100% !important; }
code { font-size: 10pt !important; background: #f5f5f5 !important; padding: 1pt 3pt !important; border: 0.5pt solid #ddd !important; font-family: 'Courier New', monospace !important; }
.print-header { display: block !important; text-align: center; font-family: 'Times New Roman', Times, serif !important; padding-bottom: 5pt; margin-bottom: 8pt; border-bottom: 0.75pt solid #999; }
.print-header .ph-line { font-size: 10pt; color: #555; letter-spacing: 0.02em; }
h2, h3, h4 { page-break-after: avoid !important; }
}
</style>
</head>
<body>
<a href="#main-content" class="skip-link">Skip to main content</a>
<nav class="navbar navbar-expand-lg sticky-top dip-navbar" id="mainNav" aria-label="Main navigation">
<div class="container">
<a class="navbar-brand fw-semibold" href="./index.html">DIP Lab</a>
<button class="navbar-toggler border-0" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation"><span class="navbar-toggler-icon"></span></button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav ms-auto gap-1">
<li class="nav-item"><a class="nav-link" href="./index.html" data-page="index">Home</a></li>
<li class="nav-item"><a class="nav-link" href="./p1.html" data-page="p1">P1</a></li>
<li class="nav-item"><a class="nav-link" href="./p2.html" data-page="p2">P2</a></li>
<li class="nav-item"><a class="nav-link" href="./p3.html" data-page="p3">P3</a></li>
<li class="nav-item"><a class="nav-link" href="./p4.html" data-page="p4">P4</a></li>
<li class="nav-item"><a class="nav-link" href="./p5.html" data-page="p5">P5</a></li>
<li class="nav-item"><a class="nav-link" href="./p6.html" data-page="p6">P6</a></li>
<li class="nav-item"><a class="nav-link" href="./p7.html" data-page="p7">P7</a></li>
<li class="nav-item"><a class="nav-link" href="./p8.html" data-page="p8">P8</a></li>
</ul>
<button id="themeToggle" class="btn btn-sm ms-3 theme-toggle" type="button" aria-label="Toggle theme"><span class="theme-toggle-label">Dark</span></button>
</div>
</div>
</nav>
<!-- Print cover page -->
<div class="print-only print-cover" aria-hidden="true">
<img class="cover-logo" src="https://shooliniuniversity.com/assets/images/logo.png" alt="Shoolini University Logo">
<div class="cover-university">Shoolini University</div>
<div class="cover-dept">Faculty of Engineering & Technology<br>Department of Computer Science & Engineering</div>
<div class="cover-rule"></div>
<div class="cover-subject">Digital Image Processing</div>
<div class="cover-code">Course Code: CSU2543</div>
<div class="cover-practical">Practical 3: Image Negation, Subtraction & Inversion</div>
<table class="cover-table">
<tr><td>Submitted by:</td><td>Divya Mohan</td></tr>
<tr><td>Programme:</td><td>B.Tech CSE (Cybersecurity)</td></tr>
<tr><td>Semester:</td><td>8th</td></tr>
<tr><td>Faculty Guide:</td><td>Ishani Sharma</td></tr>
<tr><td>Reference Text:</td><td>Gonzalez & Woods, <em>Digital Image Processing</em>, 3rd Ed.</td></tr>
</table>
<div class="cover-rule-sm"></div>
<div class="cover-session">Academic Session 2025–2026</div>
</div>
<!-- Print running header -->
<div class="print-only print-header" aria-hidden="true">
<div class="ph-line">Shoolini University · CSU2543 · Digital Image Processing · Divya Mohan</div>
</div>
<main id="main-content">
<div class="container">
<h2>Practical 3: Negation, Subtraction & Inversion</h2>
<p class="no-print" style="margin-bottom:1rem"><a href="https://colab.research.google.com/github/divyamohan1993/dip-practical/blob/main/Practical_3.ipynb" target="_blank" rel="noopener"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab" style="height:20px;vertical-align:middle"></a> <span style="font-size:0.8rem;color:var(--text-muted)">Run this practical in Google Colab</span></p>
<!-- Theory -->
<div class="section-card">
<h3>Objective</h3>
<p>To implement and analyze fundamental intensity transformation operations: image negation, image subtraction, and intensity inversion.</p>
<div class="theory-box">
<strong>Theory:</strong> Intensity transformations are point operations that modify pixel values individually.
<strong>Negation</strong> reverses the intensity scale: \(s = (L-1) - r\), useful for enhancing detail in dark regions.
<strong>Image subtraction</strong> \(g = |f_1 - f_2|\) reveals differences between two images, widely used in medical imaging (Digital Subtraction Angiography).
</div>
<div class="formula-box">$$s = (L-1) - r$$</div>
</div>
<!-- Part 1: Image Negation -->
<div class="section-card">
<h3>Part 1: Image Negation (s = 255 - r)</h3>
<p>Compute the negative of an image by inverting all pixel intensities.</p>
<div class="picker-bar" id="mainPicker"></div>
<button class="btn-run" id="btnNegate" disabled>Negate Image</button>
<div id="negateResult"></div>
</div>
<!-- Part 2: Image Subtraction -->
<div class="section-card">
<h3>Part 2: Image Subtraction |Img1 - Img2|</h3>
<p>Compute the absolute difference between two images to reveal hidden structures.</p>
<div class="picker-bar">
<div id="picker1"></div>
<div id="picker2"></div>
</div>
<button class="btn-run" id="btnSubtract" disabled>Subtract Images</button>
<div id="subtractResult"></div>
</div>
<!-- Part 3: Complete Pipeline -->
<div class="section-card">
<h3>Part 3: Complete Pipeline (Subtraction → Negation → Enhancement)</h3>
<p>Run the full pipeline on the selected image pair: subtraction, then negation of result, then contrast stretching for enhancement.</p>
<button class="btn-run" id="btnPipeline" disabled>Run Pipeline</button>
<div id="pipelineResult"></div>
</div>
<!-- Analysis Questions -->
<div class="analysis-box">
<h4>Analysis Questions</h4>
<ol>
<li>In the angiography example, what structures become visible after subtraction that were not visible in either original image?</li>
<li>Why is absolute difference used instead of simple subtraction? What would happen with signed vs unsigned arithmetic?</li>
<li>Compare the histogram of the original image with its negative. What mathematical relationship exists between them?</li>
</ol>
</div>
</div>
</main>
<footer class="site-footer" aria-label="Site footer">
<div class="container">
<p>CSU2543 Digital Image Processing · Shoolini University · Divya Mohan · Ishani Sharma</p>
</div>
</footer>
<div id="toast" class="toast" role="status" aria-live="polite" aria-atomic="true"></div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>
<script src="./js/core.js"></script>
<script src="./js/theme.js"></script>
<script src="./js/nav.js"></script>
<script src="./js/interactive.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js@4/dist/chart.umd.min.js"></script>
<script src="./js/dip.js"></script>
<script src="./js/plot.js"></script>
<script src="./js/picker.js"></script>
<script>
(async function () {
'use strict';
function showError(container, message) {
container.textContent = '';
var p = document.createElement('p');
p.style.color = 'var(--error)';
p.textContent = 'Error: ' + message;
container.appendChild(p);
}
function cropToCommon(img1, img2) {
var w = Math.min(img1.width, img2.width);
var h = Math.min(img1.height, img2.height);
var g1 = img1.gray;
var g2 = img2.gray;
if (img1.width !== w || img1.height !== h) {
var tmp = new Uint8Array(w * h);
for (var y = 0; y < h; y++)
for (var x = 0; x < w; x++)
tmp[y * w + x] = g1[y * img1.width + x];
g1 = tmp;
}
if (img2.width !== w || img2.height !== h) {
var tmp = new Uint8Array(w * h);
for (var y = 0; y < h; y++)
for (var x = 0; x < w; x++)
tmp[y * w + x] = g2[y * img2.width + x];
g2 = tmp;
}
return { g1: g1, g2: g2, w: w, h: h };
}
// Part 1: Main picker for negation
var mainPicker = await DIP.createPicker('mainPicker', {
label: 'Image',
defaultImage: 'partial_body',
onReady: function () {
document.getElementById('btnNegate').disabled = false;
}
});
// Part 2: Two pickers for subtraction
var picker1 = await DIP.createPicker('picker1', {
label: 'Image 1',
defaultImage: 'angiography_mask',
onReady: function () {
document.getElementById('btnSubtract').disabled = false;
document.getElementById('btnPipeline').disabled = false;
}
});
var picker2 = await DIP.createPicker('picker2', {
label: 'Image 2',
defaultImage: 'angiography_live'
});
// --- Part 1: Image Negation ---
document.getElementById('btnNegate').addEventListener('click', async function () {
var btn = this;
var sel = mainPicker.getSelection();
if (!sel.filename) return DIP.showToast('Select an image first');
var container = document.getElementById('negateResult');
DIP.setLoading(container, true);
btn.disabled = true;
try {
var img = await DIP.loadImage(sel.url);
var negated = DIP.negate(img.gray);
var panels = DIP.figure(container, 'Image Negation', 2, [
{ type: 'image', title: 'Original' },
{ type: 'image', title: 'Negated (s = 255 - r)' },
{ type: 'chart', title: 'Original Histogram' },
{ type: 'chart', title: 'Negated Histogram' }
]);
DIP.draw.gray(panels[0].canvas, img.gray, img.width, img.height);
DIP.draw.gray(panels[1].canvas, negated, img.width, img.height);
DIP.chart.histogram(panels[2].canvas, img.gray, { title: 'Original Histogram', color: 'rgba(70,130,180,0.85)' });
DIP.chart.histogram(panels[3].canvas, negated, { title: 'Negated Histogram', color: 'rgba(220,80,80,0.85)' });
} catch (e) {
showError(container, e.message);
}
DIP.setLoading(container, false);
btn.disabled = false;
});
// --- Part 2: Image Subtraction ---
document.getElementById('btnSubtract').addEventListener('click', async function () {
var btn = this;
var s1 = picker1.getSelection();
var s2 = picker2.getSelection();
if (!s1.filename || !s2.filename) return DIP.showToast('Select both images');
var container = document.getElementById('subtractResult');
DIP.setLoading(container, true);
btn.disabled = true;
try {
var img1 = await DIP.loadImage(s1.url);
var img2 = await DIP.loadImage(s2.url);
var common = cropToCommon(img1, img2);
var diff = DIP.subtract(common.g1, common.g2);
var panels = DIP.figure(container, 'Image Subtraction |Img1 - Img2|', 3, [
{ type: 'image', title: 'Image 1' },
{ type: 'image', title: 'Image 2' },
{ type: 'image', title: '|Img1 - Img2|' }
]);
DIP.draw.gray(panels[0].canvas, common.g1, common.w, common.h);
DIP.draw.gray(panels[1].canvas, common.g2, common.w, common.h);
DIP.draw.gray(panels[2].canvas, diff, common.w, common.h);
} catch (e) {
showError(container, e.message);
}
DIP.setLoading(container, false);
btn.disabled = false;
});
// --- Part 3: Complete Pipeline ---
document.getElementById('btnPipeline').addEventListener('click', async function () {
var btn = this;
var s1 = picker1.getSelection();
var s2 = picker2.getSelection();
if (!s1.filename || !s2.filename) return DIP.showToast('Select both images in Part 2 first');
var container = document.getElementById('pipelineResult');
DIP.setLoading(container, true);
btn.disabled = true;
try {
var img1 = await DIP.loadImage(s1.url);
var img2 = await DIP.loadImage(s2.url);
var common = cropToCommon(img1, img2);
// Pipeline: subtract -> negate -> contrast stretch
var diff = DIP.subtract(common.g1, common.g2);
var negated = DIP.negate(diff);
var enhanced = DIP.contrastStretch(negated);
var panels = DIP.figure(container, 'Complete Pipeline: Subtract \u2192 Negate \u2192 Contrast Stretch', 4, [
{ type: 'image', title: 'Image 1' },
{ type: 'image', title: 'Image 2' },
{ type: 'image', title: '|Img1 - Img2|' },
{ type: 'image', title: 'Enhanced Result' }
]);
DIP.draw.gray(panels[0].canvas, common.g1, common.w, common.h);
DIP.draw.gray(panels[1].canvas, common.g2, common.w, common.h);
DIP.draw.gray(panels[2].canvas, diff, common.w, common.h);
DIP.draw.gray(panels[3].canvas, enhanced, common.w, common.h);
} catch (e) {
showError(container, e.message);
}
DIP.setLoading(container, false);
btn.disabled = false;
});
})();
</script>
</body>
</html>