ssim.js 4.0.1 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (151) hide show
  1. package/CLA.md +66 -0
  2. package/CONTRIBUTING.md +119 -0
  3. package/LICENSE +1 -1
  4. package/LICENSES/LIVE Images Database +18 -0
  5. package/LICENSES/Subjective quality assessment - IVC database +5 -0
  6. package/LICENSES/Wang et al SSIM +24 -0
  7. package/LICENSES/bezkrovny +49 -0
  8. package/LICENSES/cell2csv +2 -0
  9. package/LICENSES/obartra-ssim +21 -0
  10. package/LICENSES/rhys-e +21 -0
  11. package/README.md +216 -34
  12. package/dist/bezkrovnySsim.d.ts +5 -19
  13. package/dist/bezkrovnySsim.js +113 -72
  14. package/dist/bezkrovnySsim.js.map +1 -1
  15. package/dist/browser.d.mts +9 -0
  16. package/dist/browser.d.ts +9 -0
  17. package/dist/browser.js +37 -0
  18. package/dist/browser.js.map +1 -0
  19. package/dist/browser.mjs +742 -0
  20. package/dist/browser.mjs.map +7 -0
  21. package/dist/defaults.d.ts +3 -1
  22. package/dist/defaults.js +14 -4
  23. package/dist/defaults.js.map +1 -1
  24. package/dist/gaussian.d.ts +2 -0
  25. package/dist/gaussian.js +168 -0
  26. package/dist/gaussian.js.map +1 -0
  27. package/dist/gaussianSymmetric.d.ts +3 -0
  28. package/dist/gaussianSymmetric.js +62 -0
  29. package/dist/gaussianSymmetric.js.map +1 -0
  30. package/dist/index.d.mts +9 -0
  31. package/dist/index.d.ts +8 -19
  32. package/dist/index.js +19 -88
  33. package/dist/index.js.map +1 -1
  34. package/dist/index.mjs +718 -0
  35. package/dist/index.mjs.map +7 -0
  36. package/dist/options.d.ts +2 -0
  37. package/dist/options.js +60 -0
  38. package/dist/options.js.map +1 -0
  39. package/dist/originalSsim.d.ts +3 -26
  40. package/dist/originalSsim.js +5 -57
  41. package/dist/originalSsim.js.map +1 -1
  42. package/dist/pixels.d.ts +5 -0
  43. package/dist/pixels.js +157 -0
  44. package/dist/pixels.js.map +1 -0
  45. package/dist/prepare.d.ts +7 -0
  46. package/dist/prepare.js +48 -0
  47. package/dist/prepare.js.map +1 -0
  48. package/dist/referenceSsim.d.ts +4 -0
  49. package/dist/referenceSsim.js +59 -0
  50. package/dist/referenceSsim.js.map +1 -0
  51. package/dist/result.d.ts +2 -0
  52. package/dist/result.js +20 -0
  53. package/dist/result.js.map +1 -0
  54. package/dist/ssim.d.ts +3 -21
  55. package/dist/ssim.js +4 -126
  56. package/dist/ssim.js.map +1 -1
  57. package/dist/ssim.web.js +2 -2
  58. package/dist/ssim.web.js.map +7 -1
  59. package/dist/types.d.ts +27 -7
  60. package/dist/weberSsim.d.ts +19 -0
  61. package/dist/weberSsim.js +119 -0
  62. package/dist/weberSsim.js.map +1 -0
  63. package/package.json +116 -1
  64. package/src/bezkrovnySsim.ts +133 -67
  65. package/src/browser.ts +49 -0
  66. package/src/defaults.ts +16 -6
  67. package/src/gaussian.ts +228 -0
  68. package/src/gaussianSymmetric.ts +95 -0
  69. package/src/index.ts +47 -96
  70. package/src/options.ts +74 -0
  71. package/src/originalSsim.ts +9 -79
  72. package/src/pixels.ts +198 -0
  73. package/src/prepare.ts +73 -0
  74. package/src/referenceSsim.ts +71 -0
  75. package/src/result.ts +23 -0
  76. package/src/ssim.ts +9 -168
  77. package/src/types.ts +44 -15
  78. package/src/weberSsim.ts +132 -0
  79. package/dist/downsample.d.ts +0 -12
  80. package/dist/downsample.js +0 -70
  81. package/dist/downsample.js.map +0 -1
  82. package/dist/math.d.ts +0 -155
  83. package/dist/math.js +0 -394
  84. package/dist/math.js.map +0 -1
  85. package/dist/matlab/conv2.d.ts +0 -137
  86. package/dist/matlab/conv2.js +0 -250
  87. package/dist/matlab/conv2.js.map +0 -1
  88. package/dist/matlab/filter2.d.ts +0 -18
  89. package/dist/matlab/filter2.js +0 -53
  90. package/dist/matlab/filter2.js.map +0 -1
  91. package/dist/matlab/fspecial.d.ts +0 -39
  92. package/dist/matlab/fspecial.js +0 -102
  93. package/dist/matlab/fspecial.js.map +0 -1
  94. package/dist/matlab/imfilter.d.ts +0 -24
  95. package/dist/matlab/imfilter.js +0 -84
  96. package/dist/matlab/imfilter.js.map +0 -1
  97. package/dist/matlab/index.d.ts +0 -23
  98. package/dist/matlab/index.js +0 -29
  99. package/dist/matlab/index.js.map +0 -1
  100. package/dist/matlab/internal/numbers.d.ts +0 -14
  101. package/dist/matlab/internal/numbers.js +0 -28
  102. package/dist/matlab/internal/numbers.js.map +0 -1
  103. package/dist/matlab/mod.d.ts +0 -21
  104. package/dist/matlab/mod.js +0 -27
  105. package/dist/matlab/mod.js.map +0 -1
  106. package/dist/matlab/normpdf.d.ts +0 -36
  107. package/dist/matlab/normpdf.js +0 -55
  108. package/dist/matlab/normpdf.js.map +0 -1
  109. package/dist/matlab/ones.d.ts +0 -15
  110. package/dist/matlab/ones.js +0 -22
  111. package/dist/matlab/ones.js.map +0 -1
  112. package/dist/matlab/padarray.d.ts +0 -37
  113. package/dist/matlab/padarray.js +0 -349
  114. package/dist/matlab/padarray.js.map +0 -1
  115. package/dist/matlab/rgb2gray.d.ts +0 -15
  116. package/dist/matlab/rgb2gray.js +0 -58
  117. package/dist/matlab/rgb2gray.js.map +0 -1
  118. package/dist/matlab/skip2d.d.ts +0 -34
  119. package/dist/matlab/skip2d.js +0 -55
  120. package/dist/matlab/skip2d.js.map +0 -1
  121. package/dist/matlab/sub.d.ts +0 -17
  122. package/dist/matlab/sub.js +0 -33
  123. package/dist/matlab/sub.js.map +0 -1
  124. package/dist/matlab/transpose.d.ts +0 -18
  125. package/dist/matlab/transpose.js +0 -34
  126. package/dist/matlab/transpose.js.map +0 -1
  127. package/dist/matlab/zeros.d.ts +0 -15
  128. package/dist/matlab/zeros.js +0 -22
  129. package/dist/matlab/zeros.js.map +0 -1
  130. package/dist/version.d.ts +0 -2
  131. package/dist/version.js +0 -5
  132. package/dist/version.js.map +0 -1
  133. package/src/downsample.ts +0 -81
  134. package/src/math.ts +0 -447
  135. package/src/matlab/conv2.ts +0 -272
  136. package/src/matlab/filter2.ts +0 -52
  137. package/src/matlab/fspecial.ts +0 -107
  138. package/src/matlab/imfilter.ts +0 -93
  139. package/src/matlab/index.ts +0 -23
  140. package/src/matlab/internal/numbers.ts +0 -28
  141. package/src/matlab/mod.ts +0 -23
  142. package/src/matlab/normpdf.ts +0 -57
  143. package/src/matlab/ones.ts +0 -19
  144. package/src/matlab/padarray.ts +0 -375
  145. package/src/matlab/rgb2gray.ts +0 -65
  146. package/src/matlab/skip2d.ts +0 -58
  147. package/src/matlab/sub.ts +0 -38
  148. package/src/matlab/transpose.ts +0 -33
  149. package/src/matlab/zeros.ts +0 -19
  150. package/src/types/bmp-js.d.ts +0 -1
  151. package/src/version.ts +0 -2
@@ -1,375 +0,0 @@
1
- import { Matrix } from "../types";
2
- import { mod } from "./mod";
3
-
4
- /**
5
- * Mirrors a matrix horizontally.
6
- *
7
- * @example
8
- * 1 2 3 4 becomes: 4 3 2 1
9
- * 5 6 7 8 8 7 6 5
10
- *
11
- * @method mirrorHorizonal
12
- * @param {Matrix} A - The input matrix
13
- * @returns {Matrix} B - The rotated matrix
14
- * @private
15
- * @memberOf matlab
16
- * @since 0.0.2
17
- */
18
- function mirrorHorizonal({ data: ref, width, height }: Matrix): Matrix {
19
- const data = new Array(ref.length);
20
-
21
- for (let x = 0; x < height; x++) {
22
- for (let y = 0; y < width; y++) {
23
- data[x * width + y] = ref[x * width + width - 1 - y];
24
- }
25
- }
26
-
27
- return {
28
- data,
29
- width,
30
- height
31
- };
32
- }
33
-
34
- /**
35
- * Mirrors a matrix vertically.
36
- *
37
- * @example
38
- * 1 2 3 4 becomes: 9 0 F E
39
- * 5 6 7 8 5 6 7 8
40
- * 9 0 F E 1 2 3 4
41
- *
42
- * @method mirrorVertical
43
- * @param {Matrix} A - The input matrix
44
- * @returns {Matrix} B - The rotated matrix
45
- * @private
46
- * @memberOf matlab
47
- * @since 0.0.2
48
- */
49
- function mirrorVertical({ data: ref, width, height }: Matrix): Matrix {
50
- const data = new Array(ref.length);
51
-
52
- for (let x = 0; x < height; x++) {
53
- for (let y = 0; y < width; y++) {
54
- data[x * width + y] = ref[(height - 1 - x) * width + y];
55
- }
56
- }
57
-
58
- return {
59
- data,
60
- width,
61
- height
62
- };
63
- }
64
-
65
- /**
66
- * Concatenates 2 matrices of the same height horizontally.
67
- *
68
- * @example
69
- * 1 2 3 4 becomes: 1 2 3 4
70
- * 5 6 7 8 5 6 7 8
71
- *
72
- * @method concatHorizontal
73
- * @param {Matrix} A - The first matrix
74
- * @param {Matrix} B - The second matrix
75
- * @returns {Matrix} out - The combined matrix
76
- * @private
77
- * @memberOf matlab
78
- * @since 0.0.2
79
- */
80
- function concatHorizontal(A: Matrix, B: Matrix): Matrix {
81
- const width = A.width + B.width;
82
- const data = new Array(A.height * width);
83
-
84
- for (let x = 0; x < A.height; x++) {
85
- for (let y = 0; y < A.width; y++) {
86
- data[x * width + y] = A.data[x * A.width + y];
87
- }
88
- for (let y = 0; y < B.width; y++) {
89
- data[x * width + y + A.width] = B.data[x * B.width + y];
90
- }
91
- }
92
-
93
- return {
94
- data,
95
- width,
96
- height: A.height
97
- };
98
- }
99
-
100
- /**
101
- * Concatenates 2 matrices of the same height vertically.
102
- *
103
- * @example
104
- * 1 2 3 4 becomes: 1 2
105
- * 5 6 7 8 5 6
106
- * 3 4
107
- * 7 8
108
- *
109
- * @method concatVertical
110
- * @param {Matrix} A - The first matrix
111
- * @param {Matrix} B - The second matrix
112
- * @returns {Matrix} out - The combined matrix
113
- * @private
114
- * @memberOf matlab
115
- * @since 0.0.2
116
- */
117
- function concatVertical(A: Matrix, B: Matrix): Matrix {
118
- return {
119
- data: A.data.concat(B.data),
120
- height: A.height + B.height,
121
- width: A.width
122
- };
123
- }
124
-
125
- /**
126
- * Adds 2 * `pad` cells to a matrix horizontally. The values used are mirrored from the input
127
- * matrix.
128
- *
129
- * @example
130
- * with padding 1:
131
- * 1 2 3 4 becomes: 1 1 2 3 4 4
132
- * 5 6 7 8 5 5 6 7 8 8
133
- *
134
- * With padding 2:
135
- * 1 2 3 4 becomes: 2 1 1 2 3 4 4 3
136
- * 5 6 7 8 6 5 5 6 7 8 8 7
137
- *
138
- * @method padHorizontal
139
- * @param {Matrix} A - The input matrix
140
- * @param {Number} pad - The nummber of cells to add to each side (left / right)
141
- * @returns {Matrix} B - The padded matrix
142
- * @private
143
- * @memberOf matlab
144
- * @since 0.0.2
145
- */
146
- function padHorizontal(A: Matrix, pad: number): Matrix {
147
- const width = A.width + 2 * pad;
148
- const data = new Array(width * A.height);
149
- const mirrored = concatHorizontal(A, mirrorHorizonal(A));
150
-
151
- for (let x = 0; x < A.height; x++) {
152
- for (let y = -pad; y < A.width + pad; y++) {
153
- data[x * width + y + pad] =
154
- mirrored.data[x * mirrored.width + mod(y, mirrored.width)];
155
- }
156
- }
157
-
158
- return {
159
- data,
160
- width,
161
- height: A.height
162
- };
163
- }
164
-
165
- /**
166
- * Adds 2 * `pad` cells to a matrix vertically. The values used are mirrored from the input
167
- * matrix.
168
- *
169
- * @example
170
- * with padding 1:
171
- * 1 2 3 4 becomes: 1 2 3 4
172
- * 5 6 7 8 1 2 3 4
173
- * 5 6 7 8
174
- * 5 6 7 8
175
- * With padding 2:
176
- * 1 2 3 4 becomes: 5 6 7 8
177
- * 5 6 7 8 1 2 3 4
178
- * 1 2 3 4
179
- * 5 6 7 8
180
- * 5 6 7 8
181
- * 1 2 3 4
182
- *
183
- * @method padVertical
184
- * @param {Matrix} A - The input matrix
185
- * @param {Number} pad - The nummber of cells to add to each side (top / bottom)
186
- * @returns {Matrix} B - The padded matrix
187
- * @private
188
- * @memberOf matlab
189
- * @since 0.0.2
190
- */
191
- function padVertical(A: Matrix, pad: number): Matrix {
192
- const mirrored = concatVertical(A, mirrorVertical(A));
193
- const height = A.height + pad * 2;
194
- const data = new Array(A.width * height);
195
-
196
- for (let x = -pad; x < A.height + pad; x++) {
197
- for (let y = 0; y < A.width; y++) {
198
- data[(x + pad) * A.width + y] =
199
- mirrored.data[mod(x, mirrored.height) * A.width + y];
200
- }
201
- }
202
-
203
- return {
204
- data,
205
- width: A.width,
206
- height
207
- };
208
- }
209
-
210
- /**
211
- * Implements `padarray` matching Matlab only for the case where:
212
- *
213
- * `padHeight <= A.height && padWidth <= A.width`
214
- *
215
- * For an input Matrix `E`, we add padding A, B, C, D, F, G, H and I of size `padHeight` and
216
- * `padWidth` where appropriate. For instance, given E:
217
- *
218
- * 1 2 3
219
- * 4 5 6
220
- *
221
- * Placed in a padding matrix like this:
222
- *
223
- * | A | B | C |
224
- * |---|---|---|
225
- * | D | E | F |
226
- * |---|---|---|
227
- * | G | H | I |
228
- *
229
- * with padding [1, 1] it becomes:
230
- *
231
- * | 1 | 1 2 3 | 3 |
232
- * |---|-------|---|
233
- * | 1 | 1 2 3 | 3 |
234
- * | 4 | 4 5 6 | 6 |
235
- * |---|-------|---|
236
- * | 4 | 4 5 6 | 6 |
237
- *
238
- * with padding [2, 3] it becomes:
239
- *
240
- * | 6 5 4 | 4 5 6 | 6 5 4 |
241
- * | 3 2 1 | 1 2 3 | 3 2 1 |
242
- * |-------|-------|-------|
243
- * | 3 2 1 | 1 2 3 | 3 2 1 |
244
- * | 6 5 4 | 4 5 6 | 6 5 4 |
245
- * |-------|-------|-------|
246
- * | 6 5 4 | 4 5 6 | 6 5 4 |
247
- * | 3 2 1 | 1 2 3 | 3 2 1 |
248
- *
249
- * @method fastPadding
250
- * @param {Matrix} A - The input matrix
251
- * @param {Array<number>} padding - An array where the first element is the padding to apply to each
252
- * side on each row and the second one is the vertical padding for each side of each column
253
- * @returns {Matrix} B - The padded matrix
254
- * @private
255
- * @memberOf matlab
256
- * @since 0.0.4
257
- */
258
- function fastPadding(
259
- A: Matrix,
260
- [padHeight, padWidth]: [number, number]
261
- ): Matrix {
262
- const width = A.width + padWidth * 2;
263
- const height = A.height + padHeight * 2;
264
- const data = new Array(width * height);
265
-
266
- for (let x = -padHeight; x < 0; x++) {
267
- // A
268
- for (let y = -padWidth; y < 0; y++) {
269
- data[(x + padHeight) * width + y + padWidth] =
270
- A.data[(Math.abs(x) - 1) * A.width + Math.abs(y) - 1];
271
- }
272
- // B
273
- for (let y = 0; y < A.width; y++) {
274
- data[(x + padHeight) * width + y + padWidth] =
275
- A.data[(Math.abs(x) - 1) * A.width + y];
276
- }
277
- // C
278
- for (let y = A.width; y < A.width + padWidth; y++) {
279
- data[(x + padHeight) * width + y + padWidth] =
280
- A.data[(Math.abs(x) - 1) * A.width + 2 * A.width - y - 1];
281
- }
282
- }
283
-
284
- for (let x = 0; x < A.height; x++) {
285
- // D
286
- for (let y = -padWidth; y < 0; y++) {
287
- data[(x + padHeight) * width + y + padWidth] =
288
- A.data[x * A.width + Math.abs(y) - 1];
289
- }
290
- // E
291
- for (let y = 0; y < A.width; y++) {
292
- data[(x + padHeight) * width + y + padWidth] = A.data[x * A.width + y];
293
- }
294
- // F
295
- for (let y = A.width; y < A.width + padWidth; y++) {
296
- data[(x + padHeight) * width + y + padWidth] =
297
- A.data[x * A.width + 2 * A.width - y - 1];
298
- }
299
- }
300
-
301
- for (let x = A.height; x < A.height + padHeight; x++) {
302
- // G
303
- for (let y = -padWidth; y < 0; y++) {
304
- data[(x + padHeight) * width + y + padWidth] =
305
- A.data[(2 * A.height - x - 1) * A.width + Math.abs(y) - 1];
306
- }
307
- // H
308
- for (let y = 0; y < A.width; y++) {
309
- data[(x + padHeight) * width + y + padWidth] =
310
- A.data[(2 * A.height - x - 1) * A.width + y];
311
- }
312
- // I
313
- for (let y = A.width; y < A.width + padWidth; y++) {
314
- data[(x + padHeight) * width + y + padWidth] =
315
- A.data[(2 * A.height - x - 1) * A.width + 2 * A.width - y - 1];
316
- }
317
- }
318
-
319
- return {
320
- data,
321
- width,
322
- height
323
- };
324
- }
325
-
326
- export type PaddingValue = "symmetric";
327
- export type PaddingDirection = "both";
328
- /**
329
- * `B = padarray(A,padsize)` pads array `A`. padsize is a vector of nonnegative integers that
330
- * specifies both, the amount of padding to add and the dimension along which to add it. The value
331
- * of an element in the vector specifies the amount of padding to add. The order of the element in
332
- * the vector specifies the dimension along which to add the padding.
333
- *
334
- * For example, a padsize value of `[2 3]` means add 2 elements of padding along the first dimension
335
- * and 3 elements of padding along the second dimension.
336
- *
337
- * By default, paddarray adds padding before the first element and after the last element along the
338
- * specified dimension.
339
- *
340
- * `B = padarray(A,padsize,padval)` pads array `A` where `padval` specifies the value to use as the
341
- * pad value. `padval` can only be 'symmetric' for this implementation of `padarray` which will pad
342
- * the array with mirror reflections of itself.
343
- *
344
- * This method mimics Matlab's `padarray` method with `padval = 'symmetric'` and
345
- * `direction = 'both'`. No other options have been implemented and, if set, they will be ignored.
346
- *
347
- * This method has been unfolded for performance and switched to simple for loops. Readability
348
- * suffers.
349
- *
350
- * @method padarray
351
- * @param {Matrix} A - The target matrix
352
- * @param {Array<number>} padding - An array where the first element is the padding to apply to
353
- * each side on each row and the second one is the vertical padding for each side of each column
354
- * @param {String} [padval='symmetric'] - The type of padding to apply (coerced to 'symmetric')
355
- * @param {String} [direction='both'] - The direction to which apply padding (coerced to 'both')
356
- * @returns {Matrix} c - An array with padding added on each side.
357
- * @public
358
- * @memberOf matlab
359
- * @since 0.0.2
360
- */
361
- export function padarray(
362
- A: Matrix,
363
- [padHeight, padWidth]: [number, number],
364
- _padval?: PaddingValue,
365
- _direction?: PaddingDirection
366
- ): Matrix {
367
- // If the padding to mirror is not greater than `A` dimensions, we can use `fastPadding`,
368
- // otherwise we fall back to a slower implementation that mimics Matlab behavior for longer
369
- // matrices
370
- if (A.height >= padHeight && A.width >= padWidth) {
371
- return fastPadding(A, [padHeight, padWidth]);
372
- }
373
-
374
- return padVertical(padHorizontal(A, padWidth), padHeight);
375
- }
@@ -1,65 +0,0 @@
1
- import { Matrix } from "../types";
2
-
3
- /**
4
- * For an array of pixels of the form [r, g, b] it returns the equivalent grayscale color. These
5
- * values are not derived from ITU's recommendation of [0.2126, 0.7152, 0.0722] for [r, g, b] but on
6
- * Matlab's implementation of [0.2989, 0.5870, 0.1140]
7
- *
8
- * Note that values are rounded to ensure an exact match with the original results. I think
9
- * rounding them would NOT lead to higher accuracy since the exact values for RGB to grayscale
10
- * conversion are somewhat arbitrary (as examplified by the differences between ITU and Matlab).
11
- * ± 0.5 pixel differences won't be perceptible for the human eye and will have a small impact on
12
- * SSIM. Based on some sample data changes were of the order of 10^-3.
13
- *
14
- * @method luma
15
- * @param {Number} r - The red pixel value
16
- * @param {Number} g - The green pixel value
17
- * @param {Number} b - The blue pixel value
18
- * @returns {Number} lumaValue - The value of the luminance for the [r,g,b] pixel
19
- * @private
20
- * @memberOf matlab
21
- * @since 0.0.2
22
- */
23
- function luma(r: number, g: number, b: number): number {
24
- return Math.round(0.29894 * r + 0.58704 * g + 0.11402 * b);
25
- }
26
-
27
- /**
28
- * Converts an imageData object of { width, height, data } into a 2d matrix [row, column]
29
- * where the value is the grayscale equivalent of the rgb input.
30
- *
31
- * This method mimics Matlab's `rgb2gray` method
32
- *
33
- * @method rgb2gray
34
- * @param {Matrix | ImageData} imageData - The input imageData
35
- * @returns {Object} grayscale - A grayscale representation of the input image
36
- * @public
37
- * @memberOf matlab
38
- * @since 0.0.2
39
- */
40
- export function rgb2gray({
41
- data: d,
42
- width,
43
- height
44
- }: Matrix | ImageData): Matrix {
45
- const data = new Array(width * height);
46
-
47
- for (let j = 0; j < height; j++) {
48
- for (let i = 0; i < width; i++) {
49
- const grayIndex = i + j * width;
50
- const imgIndex = grayIndex * 4;
51
-
52
- data[grayIndex] = luma(
53
- d[imgIndex],
54
- d[imgIndex + 1],
55
- d[imgIndex + 2]
56
- // d[imgIndex + 3] // ignore alpha channel
57
- );
58
- }
59
- }
60
- return {
61
- data,
62
- width,
63
- height
64
- };
65
- }
@@ -1,58 +0,0 @@
1
- import { Matrix } from "../types";
2
-
3
- /**
4
- * Generates a matrix based on input `mx` but excluding items based on their modulo and their
5
- * position in the original matrix.
6
- *
7
- * It's a crude implementation of Matlab's `A(1:f:end,1:f:end)` syntax where the first parameter
8
- * is the matrix, the next one is an array describing the rows to skip [start position, every `f`
9
- * elements an end position] and the last one follows the same syntax for columns.
10
- *
11
- * @example
12
- * ```
13
- * img1(1:f:end,1:f:end)
14
- *
15
- * ```
16
- *
17
- * becomes:
18
- *
19
- * ```
20
- * skip2d(img1, [0, f, img1.length], [0, f, img1[0].length])
21
- * ```
22
- *
23
- * Note that the start index is 0 since, unlike Matlab's, arrays start at 0. Also, unlike in Matlab,
24
- * `f` must be an integer greater than or equal to 1.
25
- *
26
- * @method skip2d
27
- * @param {Matrix} A - The input matrix
28
- * @param {Array<number>} - start row, every row, end row
29
- * @param {Array<number>} - start col, every col, end col
30
- * @returns {Matrix} B - The downsized matrix
31
- * @public
32
- * @memberOf matlab
33
- * @since 0.0.2
34
- */
35
- export function skip2d(
36
- A: Matrix,
37
- [startRow, everyRow, endRow]: [number, number, number],
38
- [startCol, everyCol, endCol]: [number, number, number]
39
- ): Matrix {
40
- const width = Math.ceil((endCol - startCol) / everyCol);
41
- const height = Math.ceil((endRow - startRow) / everyRow);
42
- const data = new Array(width * height);
43
-
44
- for (let i = 0; i < height; i++) {
45
- for (let j = 0; j < width; j++) {
46
- const Ai = startRow + i * everyRow;
47
- const Aj = startCol + j * everyCol;
48
-
49
- data[i * width + j] = A.data[Ai * A.width + Aj];
50
- }
51
- }
52
-
53
- return {
54
- data,
55
- width,
56
- height
57
- };
58
- }
package/src/matlab/sub.ts DELETED
@@ -1,38 +0,0 @@
1
- import { Matrix } from "../types";
2
-
3
- /**
4
- * Crops the matrix and returns a window at position `[x,y]` of size `[xlen, ylen]` from the input
5
- * matrix
6
- *
7
- * @method sub
8
- * @param {Matrix} A - The input matrix
9
- * @param {Number} x - The starting x offset
10
- * @param {Number} height - The vertical size of the window
11
- * @param {Number} y - The starting y offset
12
- * @param {Number} width - The horizontal size of the window
13
- * @returns {Matrix} B - The generated subwindow from matrix `c`
14
- * @public
15
- * @memberOf matlab
16
- * @since 0.0.2
17
- */
18
- export function sub(
19
- { data: ref, width: refWidth }: Matrix,
20
- x: number,
21
- height: number,
22
- y: number,
23
- width: number
24
- ): Matrix {
25
- const data = new Array(width * height);
26
-
27
- for (let i = 0; i < height; i++) {
28
- for (let j = 0; j < width; j++) {
29
- data[i * width + j] = ref[(y + i) * refWidth + x + j];
30
- }
31
- }
32
-
33
- return {
34
- data,
35
- width,
36
- height
37
- };
38
- }
@@ -1,33 +0,0 @@
1
- import { Matrix } from "../types";
2
-
3
- /**
4
- * Transposes a vector or a matrix
5
- *
6
- * This method mimics Matlab's `transpose` method (which equals to the `A.'` syntax)
7
- *
8
- * `B = A.'` returns the nonconjugate transpose of A, that is, interchanges the row and column index
9
- * for each element.
10
- *
11
- * This method does not handle complex or imaginary numbers
12
- *
13
- * @method transpose
14
- * @param {Matrix} A - The matrix to transpose
15
- * @returns {Matrix} B - The transposed matrix
16
- * @public
17
- * @memberOf matlab
18
- */
19
- export function transpose({ data: ref, width, height }: Matrix): Matrix {
20
- const data = new Array(width * height);
21
-
22
- for (let i = 0; i < height; i++) {
23
- for (let j = 0; j < width; j++) {
24
- data[j * height + i] = ref[i * width + j];
25
- }
26
- }
27
-
28
- return {
29
- data,
30
- height: width,
31
- width: height
32
- };
33
- }
@@ -1,19 +0,0 @@
1
- import { Matrix } from "../types";
2
- import { numbers } from "./internal/numbers";
3
-
4
- /**
5
- * Create a matrix of all zeros
6
- *
7
- * This method mimics Matlab's `zeros` method
8
- *
9
- * @method zeros
10
- * @param {Number} height - The height of the matrix (rows)
11
- * @param {Number} [width=height] - The width of the matrix (columns)
12
- * @returns {Matrix} B - An n-by-m matrix of zeros
13
- * @public
14
- * @memberOf matlab
15
- * @since 0.0.2
16
- */
17
- export function zeros(height: number, width: number = height): Matrix {
18
- return numbers(height, width, 0);
19
- }
@@ -1 +0,0 @@
1
- declare module "bmp-js";
package/src/version.ts DELETED
@@ -1,2 +0,0 @@
1
- export const type = "deploy"
2
- export const version = "0.0.0-semantically-released";