├── .gitignore
├── LICENSE
├── Makefile
├── README.md
├── docker-compose.test.yml
├── docker-compose.yml
├── docker
└── Dockerfile
├── notebooks
├── deep-learning
│ └── tutorials
│ │ └── pytorch-tutorial.ipynb
├── image
│ ├── features
│ │ └── local-binary-patterns.ipynb
│ ├── orientation
│ │ └── lbp-based-image-orientation.ipynb
│ └── quality
│ │ ├── brisque.ipynb
│ │ ├── brisque_svm.txt
│ │ ├── hosa.ipynb
│ │ ├── live-dataset.ipynb
│ │ └── normalize.pickle
└── recommender-system
│ └── light-fm.ipynb
└── requirements
├── requirements.dev.txt
└── requirements.txt
/.gitignore:
--------------------------------------------------------------------------------
1 | # Byte-compiled / optimized / DLL files
2 | __pycache__/
3 | *.py[cod]
4 | *$py.class
5 |
6 | # C extensions
7 | *.so
8 |
9 | # Distribution / packaging
10 | .Python
11 | build/
12 | develop-eggs/
13 | dist/
14 | downloads/
15 | eggs/
16 | .eggs/
17 | lib/
18 | lib64/
19 | parts/
20 | sdist/
21 | var/
22 | wheels/
23 | *.egg-info/
24 | .installed.cfg
25 | *.egg
26 | MANIFEST
27 |
28 | # PyInstaller
29 | # Usually these files are written by a python script from a template
30 | # before PyInstaller builds the exe, so as to inject date/other infos into it.
31 | *.manifest
32 | *.spec
33 |
34 | # Installer logs
35 | pip-log.txt
36 | pip-delete-this-directory.txt
37 |
38 | # Unit test / coverage reports
39 | htmlcov/
40 | .tox/
41 | .coverage
42 | .coverage.*
43 | .cache
44 | nosetests.xml
45 | coverage.xml
46 | *.cover
47 | .hypothesis/
48 | .pytest_cache/
49 |
50 | # Translations
51 | *.mo
52 | *.pot
53 |
54 | # Django stuff:
55 | *.log
56 | local_settings.py
57 | db.sqlite3
58 |
59 | # Flask stuff:
60 | instance/
61 | .webassets-cache
62 |
63 | # Scrapy stuff:
64 | .scrapy
65 |
66 | # Sphinx documentation
67 | docs/_build/
68 |
69 | # PyBuilder
70 | target/
71 |
72 | # Jupyter Notebook
73 | .ipynb_checkpoints
74 |
75 | # pyenv
76 | .python-version
77 |
78 | # celery beat schedule file
79 | celerybeat-schedule
80 |
81 | # SageMath parsed files
82 | *.sage.py
83 |
84 | # Environments
85 | .env
86 | .venv
87 | env/
88 | venv/
89 | ENV/
90 | env.bak/
91 | venv.bak/
92 |
93 | # Spyder project settings
94 | .spyderproject
95 | .spyproject
96 |
97 | # Rope project settings
98 | .ropeproject
99 |
100 | # mkdocs documentation
101 | /site
102 |
103 | # mypy
104 | .mypy_cache/
105 |
106 | # Jetbrains
107 | .idea
108 |
109 | # Data folder
110 | *data
111 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | clean-notebooks:
2 | echo "Cleaning notebooks"
3 | find ./ -name "*.ipynb" | xargs python3 -m nbconvert --ClearOutputPreprocessor.enabled=True --inplace
4 | echo "Removing checkpoints"
5 | find . -type d -iname .ipynb_checkpoints -exec rm -r {} +
6 |
7 | build-images:
8 | docker-compose build notebook
9 |
10 | run-tests: build-images
11 | docker-compose -f docker-compose.yml -f docker-compose.test.yml run notebook
12 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # notebooks
2 | Repository that contain my research
3 |
--------------------------------------------------------------------------------
/docker-compose.test.yml:
--------------------------------------------------------------------------------
1 | version: "3.6"
2 | services:
3 | notebook:
4 | entrypoint: "pytest --nbval-lax image/quality/brisque.ipynb"
5 |
--------------------------------------------------------------------------------
/docker-compose.yml:
--------------------------------------------------------------------------------
1 | version: "3.6"
2 | services:
3 | notebook:
4 | build:
5 | context: .
6 | dockerfile: docker/Dockerfile
7 | image: ocampor/notebook:1.0.0-base
8 | working_dir: /notebooks
9 | ports:
10 | - 8888:8888
11 | volumes:
12 | - ./notebooks:/notebooks
13 |
--------------------------------------------------------------------------------
/docker/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM jupyter/minimal-notebook:latest
2 |
3 | ADD requirements /requirements
4 |
5 | RUN pip install -r /requirements/requirements.dev.txt
6 |
--------------------------------------------------------------------------------
/notebooks/deep-learning/tutorials/pytorch-tutorial.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "code",
5 | "execution_count": null,
6 | "metadata": {},
7 | "outputs": [],
8 | "source": [
9 | "import torch"
10 | ]
11 | },
12 | {
13 | "cell_type": "code",
14 | "execution_count": null,
15 | "metadata": {},
16 | "outputs": [],
17 | "source": [
18 | "x = torch.zeros(5, 3, dtype=torch.long)"
19 | ]
20 | },
21 | {
22 | "cell_type": "code",
23 | "execution_count": null,
24 | "metadata": {},
25 | "outputs": [],
26 | "source": [
27 | "print(x.new_ones(5,3 ))"
28 | ]
29 | },
30 | {
31 | "cell_type": "code",
32 | "execution_count": null,
33 | "metadata": {},
34 | "outputs": [],
35 | "source": [
36 | "x.flatten()"
37 | ]
38 | },
39 | {
40 | "cell_type": "code",
41 | "execution_count": null,
42 | "metadata": {},
43 | "outputs": [],
44 | "source": []
45 | },
46 | {
47 | "cell_type": "code",
48 | "execution_count": null,
49 | "metadata": {},
50 | "outputs": [],
51 | "source": [
52 | "import torch\n",
53 | "import torch.nn as nn\n",
54 | "import torch.nn.functional as F\n",
55 | "\n",
56 | "\n",
57 | "class Net(nn.Module):\n",
58 | "\n",
59 | " def __init__(self):\n",
60 | " super(Net, self).__init__()\n",
61 | " # 1 input image channel, 6 output channels, 5x5 square convolution\n",
62 | " # kernel\n",
63 | " self.conv1 = nn.Conv2d(1, 6, 5)\n",
64 | " self.conv2 = nn.Conv2d(6, 16, 5)\n",
65 | " # an affine operation: y = Wx + b\n",
66 | " self.fc1 = nn.Linear(16 * 5 * 5, 120)\n",
67 | " self.fc2 = nn.Linear(120, 84)\n",
68 | " self.fc3 = nn.Linear(84, 10)\n",
69 | "\n",
70 | " def forward(self, x):\n",
71 | " # Max pooling over a (2, 2) window\n",
72 | " x = F.max_pool2d(F.relu(self.conv1(x)), (2, 2))\n",
73 | " # If the size is a square you can only specify a single number\n",
74 | " x = F.max_pool2d(F.relu(self.conv2(x)), 2)\n",
75 | " x = x.view(-1, self.num_flat_features(x))\n",
76 | " x = F.relu(self.fc1(x))\n",
77 | " x = F.relu(self.fc2(x))\n",
78 | " x = self.fc3(x)\n",
79 | " return x\n",
80 | "\n",
81 | " def num_flat_features(self, x):\n",
82 | " size = x.size()[1:] # all dimensions except the batch dimension\n",
83 | " num_features = 1\n",
84 | " for s in size:\n",
85 | " num_features *= s\n",
86 | " return num_features\n",
87 | "\n",
88 | "\n",
89 | "net = Net()\n",
90 | "print(net)"
91 | ]
92 | },
93 | {
94 | "cell_type": "code",
95 | "execution_count": null,
96 | "metadata": {},
97 | "outputs": [],
98 | "source": [
99 | "input = torch.randn(1, 1, 32, 32)\n",
100 | "out = net(input)\n",
101 | "print(out)"
102 | ]
103 | },
104 | {
105 | "cell_type": "code",
106 | "execution_count": null,
107 | "metadata": {},
108 | "outputs": [],
109 | "source": [
110 | "net.zero_grad()"
111 | ]
112 | },
113 | {
114 | "cell_type": "code",
115 | "execution_count": null,
116 | "metadata": {},
117 | "outputs": [],
118 | "source": [
119 | "out.backward(torch.randn(1, 10))"
120 | ]
121 | },
122 | {
123 | "cell_type": "code",
124 | "execution_count": null,
125 | "metadata": {},
126 | "outputs": [],
127 | "source": [
128 | "output = net(input)\n",
129 | "target = torch.randn(10) # a dummy target, for example\n",
130 | "target = target.view(1, -1) # make it the same shape as output\n",
131 | "criterion = nn.MSELoss()\n",
132 | "\n",
133 | "loss = criterion(output, target)\n",
134 | "print(loss)"
135 | ]
136 | },
137 | {
138 | "cell_type": "code",
139 | "execution_count": null,
140 | "metadata": {},
141 | "outputs": [],
142 | "source": [
143 | "loss"
144 | ]
145 | },
146 | {
147 | "cell_type": "code",
148 | "execution_count": null,
149 | "metadata": {},
150 | "outputs": [],
151 | "source": [
152 | "net.conv1.bias"
153 | ]
154 | },
155 | {
156 | "cell_type": "code",
157 | "execution_count": null,
158 | "metadata": {},
159 | "outputs": [],
160 | "source": []
161 | }
162 | ],
163 | "metadata": {
164 | "kernelspec": {
165 | "display_name": "Python 3",
166 | "language": "python",
167 | "name": "python3"
168 | },
169 | "language_info": {
170 | "codemirror_mode": {
171 | "name": "ipython",
172 | "version": 3
173 | },
174 | "file_extension": ".py",
175 | "mimetype": "text/x-python",
176 | "name": "python",
177 | "nbconvert_exporter": "python",
178 | "pygments_lexer": "ipython3",
179 | "version": "3.7.1"
180 | }
181 | },
182 | "nbformat": 4,
183 | "nbformat_minor": 2
184 | }
185 |
--------------------------------------------------------------------------------
/notebooks/image/features/local-binary-patterns.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "code",
5 | "execution_count": null,
6 | "metadata": {},
7 | "outputs": [],
8 | "source": [
9 | "import matplotlib.pyplot as plt\n",
10 | "import numpy as np\n",
11 | "import skimage.io\n",
12 | "import matplotlib.pyplot as plt\n",
13 | "from scipy import interpolate\n",
14 | "import skimage.color\n",
15 | "import skimage.transform\n",
16 | "import itertools\n",
17 | "\n",
18 | "import urllib.request as request\n",
19 | "\n",
20 | "def plot_neigborhood(x, y, P, R):\n",
21 | " plt.scatter(x, y)\n",
22 | " plt.axis('square')\n",
23 | " plt.grid(True)\n",
24 | " plt.title('Cicle with P={p} and R={r}'.format(p=P, r=R))\n",
25 | " plt.xticks(np.arange(-2, 3, 1.0))\n",
26 | " plt.yticks(np.arange(-2, 3, 1.0))\n",
27 | " plt.show()\n",
28 | " \n",
29 | "def load_image(url, as_gray=False):\n",
30 | " image_stream = request.urlopen(url)\n",
31 | " return skimage.io.imread(image_stream, as_gray=as_gray, plugin='pil')\n",
32 | "\n",
33 | "\n",
34 | "def create_index(s_T):\n",
35 | " n_ones = np.sum(s_T)\n",
36 | " s_T_size = len(s_T)\n",
37 | " \n",
38 | " if 1 in s_T:\n",
39 | " first_one = list(s_T).index(1)\n",
40 | " else:\n",
41 | " first_one = -1\n",
42 | " \n",
43 | " if 0 in s_T:\n",
44 | " first_zero = list(s_T).index(0)\n",
45 | " else:\n",
46 | " first_zero = -1\n",
47 | " \n",
48 | " if n_ones == 0:\n",
49 | " return 0\n",
50 | " elif n_ones == s_T_size:\n",
51 | " return s_T_size * (s_T_size - 1) + 1\n",
52 | " else:\n",
53 | " if first_one == 0:\n",
54 | " rot_index = n_ones - first_zero\n",
55 | " else:\n",
56 | " rot_index = s_T_size - first_one\n",
57 | " return 1 + (n_ones - 1) * s_T_size + rot_index "
58 | ]
59 | },
60 | {
61 | "cell_type": "code",
62 | "execution_count": null,
63 | "metadata": {},
64 | "outputs": [],
65 | "source": [
66 | "url = 'https://cdn.pixabay.com/photo/2015/12/26/08/20/red-1108405_1280.jpg'\n",
67 | "img = load_image(url, False)\n",
68 | "img = skimage.transform.rescale(img, scale=(1/2, 1/2), anti_aliasing=True, mode='reflect', multichannel=True)\n",
69 | "img_gray = skimage.color.rgb2gray(img)"
70 | ]
71 | },
72 | {
73 | "cell_type": "markdown",
74 | "metadata": {},
75 | "source": [
76 | "# Image Feature Extraction: Local Binary Patterns in Cython\n",
77 | "\n",
78 | "# Introduction\n",
79 | "\n",
80 | "The common goal of feature extraction is to represent the raw data as a reduced set of features that better describe their main features and attributes [1]. This way, we can reduce the dimentionality of the original input and use the new features as an input to train pattern recognition and classification techniques.\n",
81 | "\n",
82 | "Although there are several features that we can extract from a picture, Local Binary Patterns (LBP) is a theoretically simple, yet efficient approach to gray scale and rotation invariant textur classification. They work because the most frequent patterns correspond to primitive microfeatures such as edges, corners, spots, flat regions [2].\n",
83 | "\n",
84 | "In [2], Ojala et al. shown that the discrete occurence histogram of the uniform patterns are a very powerful texture feature. Image texture is defined as a two dimentional phenomenon characterized by two properties: (1) spatial structure (pattern) and (2) contrast.\n",
85 | "\n",
86 | "The image that we are going to use to test each step of the methodology is the following:"
87 | ]
88 | },
89 | {
90 | "cell_type": "code",
91 | "execution_count": null,
92 | "metadata": {},
93 | "outputs": [],
94 | "source": [
95 | "_ = plt.imshow(img)"
96 | ]
97 | },
98 | {
99 | "cell_type": "markdown",
100 | "metadata": {},
101 | "source": [
102 | "# Methodology\n",
103 | "\n",
104 | "## Circularly Symmetric Neighbor Set\n",
105 | "\n",
106 | "A circularly symmetric neighbor set for a given pixel $g_c$ is defined by the points with coordinates (i, j) that surround the central point on a circle of radius R, and number of elements P.\n",
107 | "\n",
108 | "$$i = -R\\sin\\big(\\frac{2\\pi p}{ P}\\big);\\hspace{1em}j = R\\cos\\big(\\frac{2\\pi p}{P}\\big)\\hspace{1em}\\forall\\hspace{0.5em}p \\in \\{0, 1, ..., P\\}$$"
109 | ]
110 | },
111 | {
112 | "cell_type": "code",
113 | "execution_count": null,
114 | "metadata": {},
115 | "outputs": [],
116 | "source": [
117 | "def neighborhood(P, R):\n",
118 | " x = np.arange(0, P)\n",
119 | " x = R * np.cos(2 * np.pi * x / P)\n",
120 | " \n",
121 | " y = np.arange(0, P)\n",
122 | " y = - R * np.sin(2 * np.pi * y / P)\n",
123 | " \n",
124 | " return x, y"
125 | ]
126 | },
127 | {
128 | "cell_type": "code",
129 | "execution_count": null,
130 | "metadata": {},
131 | "outputs": [],
132 | "source": [
133 | "R = 2\n",
134 | "P = 8\n",
135 | "\n",
136 | "x, y = neighborhood(P, R)\n",
137 | "\n",
138 | "plot_neigborhood(x, y, P, R)"
139 | ]
140 | },
141 | {
142 | "cell_type": "markdown",
143 | "metadata": {},
144 | "source": [
145 | "## Texture\n",
146 | "We define a texture *T* as the collection of pixels in a gray scale image\n",
147 | "\n",
148 | "$$T \\approx t(g_c, g_0, g_1, ..., g_{P-1})$$\n",
149 | "\n",
150 | "where $g_p$ corresponds to the gray value of the *p* local neighboor."
151 | ]
152 | },
153 | {
154 | "cell_type": "markdown",
155 | "metadata": {},
156 | "source": [
157 | "## Interpolation\n",
158 | "\n",
159 | "When a neighbor is not located in the center of a pixel, that neighbor gray value should be calculated by interpolation. Thus, we need to define a function that given a coordinate, returns the interpolated gray value."
160 | ]
161 | },
162 | {
163 | "cell_type": "code",
164 | "execution_count": null,
165 | "metadata": {},
166 | "outputs": [],
167 | "source": [
168 | "def interpolate2d(gray_img, kind='cubic'):\n",
169 | " \"\"\"\n",
170 | " Returns a function f(x,y) that returns the interpolated value\n",
171 | " of gray_img where (x,y) is the coordinate.\n",
172 | " \"\"\"\n",
173 | " assert gray_img.ndim == 2, 'It should be a two dimentional image (gray)'\n",
174 | " h, w = gray_img.shape\n",
175 | "\n",
176 | " x = np.arange(0, w)\n",
177 | " y = np.arange(0, h)\n",
178 | "\n",
179 | " return interpolate.interp2d(x, y, gray_img, kind=kind)\n",
180 | "\n",
181 | "def calculate_neiborhood_values(x, y, interpolation_function):\n",
182 | " gray_values = map(lambda pt: interpolation_function(*pt), zip(x, y))\n",
183 | " return np.fromiter(gray_values, float)"
184 | ]
185 | },
186 | {
187 | "cell_type": "code",
188 | "execution_count": null,
189 | "metadata": {},
190 | "outputs": [],
191 | "source": [
192 | "x0 = 400\n",
193 | "y0 = 400\n",
194 | "\n",
195 | "xp = x + x0\n",
196 | "yp = y + y0\n",
197 | "\n",
198 | "f = interpolate2d(img_gray, kind='cubic')\n",
199 | "\n",
200 | "print('Neigborhood gray values:\\n', img_gray[y0 - R: y0 + R + 1, x0 - R: x0 + R + 1])\n",
201 | "print('\\nNeighborhood interpolations:', calculate_neiborhood_values(xp, yp, f))"
202 | ]
203 | },
204 | {
205 | "cell_type": "markdown",
206 | "metadata": {},
207 | "source": [
208 | "## Achieving Gray-Scale Invariance\n",
209 | "\n",
210 | "Considering a possible loss of information, it is possible to turn the texture into the joint difference. To calculate it, we substract the gray value of the central pixel to all of the neighbor set. The joint difference distribution is a highly discriminative texture operator. It records the ocurrences of various patterns in the neighborhood of each pixel in a P-dimentional histogram.\n",
211 | "\n",
212 | "$$T \\approx t(g_0 - g_c, g_1 - g_c, ... g_{P-1} - g_c)$$\n",
213 | "\n",
214 | "where $g_0$ is the gray value of the center pixel and $g_p$ is the gray value of the $p$ neighbor. This distribution is invariant against gray-scale shifts."
215 | ]
216 | },
217 | {
218 | "cell_type": "code",
219 | "execution_count": null,
220 | "metadata": {},
221 | "outputs": [],
222 | "source": [
223 | "def joint_difference_distribution(gray_img, gc, x, y, interpolation_f):\n",
224 | " xc, yc = gc\n",
225 | " \n",
226 | " xp = xc + x\n",
227 | " yp = yc + y\n",
228 | " \n",
229 | " g_p = calculate_neiborhood_values(xp, yp, interpolation_f)\n",
230 | " g_c = interpolation_f(xc, yc)\n",
231 | " \n",
232 | " return np.round(g_p - g_c, 15)"
233 | ]
234 | },
235 | {
236 | "cell_type": "code",
237 | "execution_count": null,
238 | "metadata": {},
239 | "outputs": [],
240 | "source": [
241 | "print('The joint difference distribution is:\\n', joint_difference_distribution(img_gray, (x0, y0), x, y, f))"
242 | ]
243 | },
244 | {
245 | "cell_type": "markdown",
246 | "metadata": {},
247 | "source": [
248 | "## Local Binary Pattern\n",
249 | "\n",
250 | "$LBP_{P,R}$ operater is by definition invariant against any monotonic transformation of the gray scale. As long as the order of the gray values stays the same, the output of the $LBP_{P,R}$ operator remains constant.\n",
251 | "\n",
252 | "$$LBP_{P,R} = \\sum_{p=0}^{P-1} s(g_p - g_c) 2^p$$\n",
253 | "\n",
254 | "where \n",
255 | "\n",
256 | "$$s(x) = \n",
257 | "\\begin{cases} \n",
258 | " 1 & x\\geq0 \\\\\n",
259 | " 0 & x<0\n",
260 | "\\end{cases}\n",
261 | "$$"
262 | ]
263 | },
264 | {
265 | "cell_type": "code",
266 | "execution_count": null,
267 | "metadata": {},
268 | "outputs": [],
269 | "source": [
270 | "def binary_joint_distribution(gray_img, gc, x, y, interpolation_f):\n",
271 | " T = joint_difference_distribution(gray_img, gc, x, y, interpolation_f)\n",
272 | " return np.where(T >= 0, 1, 0)\n",
273 | "\n",
274 | "def LBP(gray_img, gc, x, y, interpolation_f):\n",
275 | " s = binary_joint_distribution(gray_img, gc, x, y, interpolation_f)\n",
276 | " p = np.arange(0, P)\n",
277 | " binomial_factor = 2 ** p\n",
278 | " return np.sum(binomial_factor * s)"
279 | ]
280 | },
281 | {
282 | "cell_type": "code",
283 | "execution_count": null,
284 | "metadata": {},
285 | "outputs": [],
286 | "source": [
287 | "print('The joint difference distribution is:\\n', joint_difference_distribution(img_gray, (x0, y0), x, y, f))\n",
288 | "print('The binary joint distribution is:\\n', binary_joint_distribution(img_gray, (x0, y0), x, y, f))\n",
289 | "print('LBP:\\n', LBP(img_gray, (x0, y0), x, y, f))"
290 | ]
291 | },
292 | {
293 | "cell_type": "markdown",
294 | "metadata": {},
295 | "source": [
296 | "### Uniform Local Binary Patterns\n",
297 | "\n",
298 | "In [2], Ojala mentions that in their practical experience LBP is not a good discriminator. They propose just to select the set of local binary patterns such that the number of spatial transitions (bitwise 0/1 changes) does not exeed 2. For example, the pattern '1111' has 0 spatial transitions, the pattern '1100' has 1 spatial transitions and the pattern '1101' has 2 spatial transitions. To each uniform pattern, a unique index is associated. \n",
299 | "\n",
300 | "The formula to create the index was borrowed from https://github.com/scikit-image/scikit-image/blob/master/skimage/feature/_texture.pyx"
301 | ]
302 | },
303 | {
304 | "cell_type": "code",
305 | "execution_count": null,
306 | "metadata": {},
307 | "outputs": [],
308 | "source": [
309 | "def is_uniform(pattern):\n",
310 | " count = 0\n",
311 | " for idx in range(len(pattern) - 1):\n",
312 | " count += pattern[idx] ^ pattern[idx + 1]\n",
313 | " if count > 2:\n",
314 | " return False\n",
315 | " return True\n",
316 | "\n",
317 | "def uniform_patterns(P):\n",
318 | " patterns = itertools.product([0, 1], repeat=P)\n",
319 | " u_patterns = [pattern for pattern in patterns if is_uniform(pattern)]\n",
320 | " \n",
321 | " return [''.join(str(elem) for elem in elems) for elems in u_patterns]\n",
322 | "\n",
323 | "def LBP_uniform(gray_img, gc, x, y, interpolation_f, uniform_patterns):\n",
324 | " s = binary_joint_distribution(gray_img, gc, x, y, f)\n",
325 | " pattern = ''.join([str(elem) for elem in s])\n",
326 | " \n",
327 | " return create_index(s) if pattern in uniform_patterns else 2 + P * (P - 1)"
328 | ]
329 | },
330 | {
331 | "cell_type": "code",
332 | "execution_count": null,
333 | "metadata": {},
334 | "outputs": [],
335 | "source": [
336 | "u_patterns = uniform_patterns(P)\n",
337 | "\n",
338 | "print('The joint difference distribution is:\\n', joint_difference_distribution(img_gray, (x0, y0), x, y, f))\n",
339 | "s_T = binary_joint_distribution(img_gray, (x0, y0), x, y, f)\n",
340 | "print('The binary joint distribution is:\\n', s_T)\n",
341 | "print('LBP:\\n', LBP(img_gray, (x0, y0), x, y, f))\n",
342 | "print('Is {} a uniform pattern: {}\\n'.format(s_T, is_uniform(s_T)))\n",
343 | "print('LBP_uniform:', LBP_uniform(img_gray, (x0, y0), x, y, f, u_patterns))"
344 | ]
345 | },
346 | {
347 | "cell_type": "markdown",
348 | "metadata": {},
349 | "source": [
350 | "Now, we can calculate the local binary patterns for a central pixel. The next step is to calculate the local binary patterns for all the fixels.\n",
351 | "\n",
352 | "*Hint: For siplicity sake, I am not considering the case where a selected index is negative (i.e. img_gray[-1][0] returns the last pixel of the first column). If we would want to have the most accurate calculation, we should consider this case and treat it. "
353 | ]
354 | },
355 | {
356 | "cell_type": "code",
357 | "execution_count": null,
358 | "metadata": {},
359 | "outputs": [],
360 | "source": [
361 | "%%time\n",
362 | "\n",
363 | "R = 2\n",
364 | "P = 8\n",
365 | "\n",
366 | "x, y = neighborhood(P, R)\n",
367 | "h, w = img_gray.shape\n",
368 | "f = interpolate2d(img_gray, kind='cubic')\n",
369 | "\n",
370 | "LBP_image = np.zeros((h, w))\n",
371 | "\n",
372 | "for j in range(h):\n",
373 | " for i in range(w):\n",
374 | " LBP_image[j, i] = LBP_uniform(img_gray, (i, j), x, y, f, u_patterns)"
375 | ]
376 | },
377 | {
378 | "cell_type": "code",
379 | "execution_count": null,
380 | "metadata": {},
381 | "outputs": [],
382 | "source": [
383 | "print('The LBP image is:', LBP_image)"
384 | ]
385 | },
386 | {
387 | "cell_type": "code",
388 | "execution_count": null,
389 | "metadata": {},
390 | "outputs": [],
391 | "source": [
392 | "_ = plt.hist(LBP_image.ravel())"
393 | ]
394 | },
395 | {
396 | "cell_type": "markdown",
397 | "metadata": {},
398 | "source": [
399 | "# Cython Code\n",
400 | "\n",
401 | "The previous code is not perfect; however, what makes it really slow is that we iterate through all the image pixels. Waiting 1 minute and 10 seconds to calculate our features is a lot, if we take into account that we have also to traini a pattern recognition technique. Thus, we need an alternative implementation that must be much faster for loops. In this case, we will use Cython. The code is presented in the next image, it is a big chunk of code. Some parts of if could be improved, but it is already much faster. Please feel free to leave comments if you don't understand something from the code.\n",
402 | "\n",
403 | "The code is written in such a way that most of it runs entirely in the C API. This strategy speeds up the execution considerably, but also allow us to take advantage of cython's parallel module. We will split the job across multiple\n",
404 | "cores in the CPU."
405 | ]
406 | },
407 | {
408 | "cell_type": "code",
409 | "execution_count": null,
410 | "metadata": {},
411 | "outputs": [],
412 | "source": [
413 | "%load_ext Cython"
414 | ]
415 | },
416 | {
417 | "cell_type": "code",
418 | "execution_count": null,
419 | "metadata": {},
420 | "outputs": [],
421 | "source": [
422 | "%%cython --compile-args=-fopenmp --link-args=-fopenmp\n",
423 | "\n",
424 | "from libc.math cimport sin, cos, pi, ceil, floor, pow\n",
425 | "from libc.stdlib cimport abort, malloc, free\n",
426 | "import numpy as np\n",
427 | "cimport numpy as np\n",
428 | "cimport cython\n",
429 | "from cython.parallel import prange, parallel\n",
430 | "cimport openmp\n",
431 | "\n",
432 | "\n",
433 | "cdef double get_pixel2d(\n",
434 | " double *image,\n",
435 | " Py_ssize_t n_rows, \n",
436 | " Py_ssize_t n_cols,\n",
437 | " long x,\n",
438 | " long y) nogil:\n",
439 | " \n",
440 | " if (y < 0) or (y >= n_rows) or (x < 0) or (x >= n_cols):\n",
441 | " return 0\n",
442 | " else:\n",
443 | " return image[y * n_cols + x]\n",
444 | "\n",
445 | " \n",
446 | "cdef double bilinear_interpolation(\n",
447 | " double *image,\n",
448 | " Py_ssize_t n_rows,\n",
449 | " Py_ssize_t n_cols,\n",
450 | " double x,\n",
451 | " double y) nogil:\n",
452 | " \n",
453 | " cdef double d_y, d_x, top_left, top_right, bottom_left, bottom_right\n",
454 | " cdef long min_y, min_x, max_y, max_x\n",
455 | "\n",
456 | " min_y = floor(y)\n",
457 | " min_x = floor(x)\n",
458 | " max_y = ceil(y)\n",
459 | " max_x = ceil(x)\n",
460 | " \n",
461 | " d_y = y - min_y\n",
462 | " d_x = x - min_x\n",
463 | " \n",
464 | " top_left = get_pixel2d(image, n_rows, n_cols, min_x, min_y)\n",
465 | " top_right = get_pixel2d(image, n_rows, n_cols, max_x, min_y)\n",
466 | " bottom_left = get_pixel2d(image, n_rows, n_cols, min_x, max_y)\n",
467 | " bottom_right = get_pixel2d(image, n_rows, n_cols, max_x, max_y)\n",
468 | " \n",
469 | " top = (1 - d_x) * top_left + d_x * top_right\n",
470 | " bottom = (1 - d_x) * bottom_left + d_x * bottom_right\n",
471 | "\n",
472 | " return (1 - d_y) * top + d_y * bottom\n",
473 | "\n",
474 | "\n",
475 | "cdef double *joint_difference_distribution(\n",
476 | " double *image,\n",
477 | " Py_ssize_t n_rows,\n",
478 | " Py_ssize_t n_cols,\n",
479 | " int x0,\n",
480 | " int y0,\n",
481 | " int P,\n",
482 | " int R\n",
483 | ") nogil:\n",
484 | " cdef Py_ssize_t p\n",
485 | " cdef double *T = malloc(sizeof(double) * P)\n",
486 | " cdef double x, y, gp, gc\n",
487 | " \n",
488 | " if T is NULL:\n",
489 | " abort()\n",
490 | " \n",
491 | " gc = get_pixel2d(image, n_rows, n_cols, x0, y0)\n",
492 | " \n",
493 | " for p in range(P):\n",
494 | " x = x0 + R * cos(2 * pi * p / P)\n",
495 | " y = y0 - R * sin(2 * pi * p / P)\n",
496 | " gp = bilinear_interpolation(image, n_rows, n_cols, x, y)\n",
497 | " T[p] = gp - gc\n",
498 | " \n",
499 | " return T\n",
500 | "\n",
501 | "\n",
502 | "cdef int *binary_joint_distribution(double *T, Py_ssize_t T_size) nogil:\n",
503 | " cdef int *s_T = malloc(sizeof(int) * T_size)\n",
504 | " cdef Py_ssize_t i = 0\n",
505 | " \n",
506 | " for t in range(T_size):\n",
507 | " if T[t] >= 0.0:\n",
508 | " s_T[t] = 1\n",
509 | " else:\n",
510 | " s_T[t] = 0\n",
511 | " \n",
512 | " return s_T\n",
513 | "\n",
514 | "\n",
515 | "cdef long LBP(double *T, int *s_T, Py_ssize_t T_size) nogil:\n",
516 | " cdef long LBP_pr = 0\n",
517 | " cdef Py_ssize_t i = 0\n",
518 | " \n",
519 | " for i in range(0, T_size):\n",
520 | " LBP_pr = LBP_pr + 2 ** i * s_T[i]\n",
521 | " \n",
522 | " return LBP_pr\n",
523 | "\n",
524 | "\n",
525 | "cdef int is_uniform_pattern(int *s_T, Py_ssize_t s_T_size) nogil:\n",
526 | " cdef Py_ssize_t i = 0\n",
527 | " cdef int counter = 0\n",
528 | " \n",
529 | " for i in range(s_T_size - 1):\n",
530 | " if s_T[i] != s_T[i + 1]:\n",
531 | " counter += 1\n",
532 | " \n",
533 | " if counter > 2:\n",
534 | " return 0\n",
535 | " return 1\n",
536 | "\n",
537 | "\n",
538 | "cdef int create_index(int *s_T, Py_ssize_t s_T_size) nogil:\n",
539 | " cdef int n_ones = 0\n",
540 | " cdef int rot_index = -1\n",
541 | " cdef int first_one = -1\n",
542 | " cdef int first_zero = -1\n",
543 | " cdef int lbp = -1\n",
544 | "\n",
545 | " cdef Py_ssize_t i\n",
546 | " for i in range(s_T_size):\n",
547 | " if s_T[i]:\n",
548 | " n_ones += 1\n",
549 | " if first_one == -1:\n",
550 | " first_one = i\n",
551 | " else:\n",
552 | " if first_zero == -1:\n",
553 | " first_zero = i\n",
554 | " \n",
555 | " if n_ones == 0:\n",
556 | " lbp = 0\n",
557 | " elif n_ones == s_T_size:\n",
558 | " lbp = s_T_size * (s_T_size - 1) + 1\n",
559 | " else:\n",
560 | " if first_one == 0:\n",
561 | " rot_index = n_ones - first_zero\n",
562 | " else:\n",
563 | " rot_index = s_T_size - first_one\n",
564 | " lbp = 1 + (n_ones - 1) * s_T_size + rot_index\n",
565 | " return lbp\n",
566 | "\n",
567 | "\n",
568 | "cdef int LBP_uniform(int *s_T, Py_ssize_t s_T_size) nogil:\n",
569 | " cdef int LBP_pru = 0\n",
570 | " cdef Py_ssize_t i = 0\n",
571 | " \n",
572 | " if is_uniform_pattern(s_T, s_T_size):\n",
573 | " LBP_pru = create_index(s_T, s_T_size)\n",
574 | " else:\n",
575 | " LBP_pru = 2 + s_T_size * (s_T_size - 1)\n",
576 | " \n",
577 | " return LBP_pru\n",
578 | "\n",
579 | "\n",
580 | "@cython.boundscheck(False)\n",
581 | "@cython.wraparound(False)\n",
582 | "def local_binary_patterns(\n",
583 | " double[:, ::1] image,\n",
584 | " int P,\n",
585 | " int R,\n",
586 | " int num_threads=1\n",
587 | "):\n",
588 | " \n",
589 | " cdef Py_ssize_t x = 0\n",
590 | " cdef Py_ssize_t y = 0\n",
591 | " cdef int n_rows = image.shape[0]\n",
592 | " cdef int n_cols = image.shape[1]\n",
593 | " cdef int[:, ::1] lbp = np.zeros([n_rows, n_cols], dtype=np.int32) \n",
594 | " \n",
595 | " with nogil, parallel(num_threads=num_threads):\n",
596 | " for y in prange(n_rows, schedule='static'):\n",
597 | " for x in prange(n_cols, schedule='static'):\n",
598 | " T = joint_difference_distribution(&image[0][0], n_rows, n_cols, x, y, P, R)\n",
599 | " s_T = binary_joint_distribution(T, P)\n",
600 | " lbp[y, x] = LBP_uniform(s_T, P)\n",
601 | " \n",
602 | " return np.asarray(lbp)"
603 | ]
604 | },
605 | {
606 | "cell_type": "code",
607 | "execution_count": null,
608 | "metadata": {},
609 | "outputs": [],
610 | "source": [
611 | "%%time\n",
612 | "\n",
613 | "lbp = local_binary_patterns(img_gray, P, R, num_threads=4)"
614 | ]
615 | },
616 | {
617 | "cell_type": "markdown",
618 | "metadata": {},
619 | "source": [
620 | "Using 4 threads, I can calculate the local binary patterns for all the pixels in less than 150 ms. This is so much more faster that I won't even bother to calculate by how many times."
621 | ]
622 | },
623 | {
624 | "cell_type": "markdown",
625 | "metadata": {},
626 | "source": [
627 | "# Comparison with a Similar Image\n",
628 | "\n",
629 | "Let's take another image of bricks, but this one will have a different texture."
630 | ]
631 | },
632 | {
633 | "cell_type": "code",
634 | "execution_count": null,
635 | "metadata": {},
636 | "outputs": [],
637 | "source": [
638 | "url2 = 'https://cdn.pixabay.com/photo/2014/09/24/16/28/bricks-459299_1280.jpg'\n",
639 | "\n",
640 | "img = load_image(url2, False)\n",
641 | "img = skimage.transform.rescale(img, scale=(1/2, 1/2), anti_aliasing=True, mode='reflect', multichannel=True)\n",
642 | "img_gray = skimage.color.rgb2gray(img)\n",
643 | "_ = plt.imshow(img)"
644 | ]
645 | },
646 | {
647 | "cell_type": "code",
648 | "execution_count": null,
649 | "metadata": {},
650 | "outputs": [],
651 | "source": [
652 | "%%time \n",
653 | "\n",
654 | "lbp2 = local_binary_patterns(img_gray, P, R, num_threads=3)"
655 | ]
656 | },
657 | {
658 | "cell_type": "code",
659 | "execution_count": null,
660 | "metadata": {},
661 | "outputs": [],
662 | "source": [
663 | "figure = plt.figure(figsize=(14, 5))\n",
664 | "\n",
665 | "plt.subplot(121)\n",
666 | "plt.hist(lbp.ravel())\n",
667 | "plt.title('Orange Bricks')\n",
668 | "plt.grid(True)\n",
669 | "\n",
670 | "plt.subplot(122)\n",
671 | "plt.hist(lbp2.ravel())\n",
672 | "plt.title('Gray Bricks')\n",
673 | "plt.grid(True)\n",
674 | "\n",
675 | "plt.show()"
676 | ]
677 | },
678 | {
679 | "cell_type": "markdown",
680 | "metadata": {},
681 | "source": [
682 | "Both histograms are very similar, and they should be, both of them are bricks. Nonetheless, features from 20 to 40 are very disimilar in both images. It means that with a good machine learning algorithm we could correctly classify them."
683 | ]
684 | },
685 | {
686 | "cell_type": "markdown",
687 | "metadata": {},
688 | "source": [
689 | "# Conclusion\n",
690 | "\n",
691 | "Local binary patterns are siple but efficient features. The theory behind is not hard to understand and they are easy to code. Nevertheless, if we code them entirely with Python, we will have some performance issues. We tackled the problem with Cython and we got very impressive results. The next step is to collect different texture images and train your favorite machine learning algorithm to classify them."
692 | ]
693 | },
694 | {
695 | "cell_type": "markdown",
696 | "metadata": {},
697 | "source": [
698 | "# Bibliography\n",
699 | "\n",
700 | "[1] Marques, O. (2011). Practical image and video processing using MATLAB. John Wiley & Sons.\n",
701 | "\n",
702 | "[2] Ojala, T., Pietikäinen, M., & Mäenpää, T. (2002). Multiresolution gray-scale and rotation invariant texture classification with local binary patterns. IEEE Transactions on Pattern Analysis and Machine Intelligence, 24(7), 971–987."
703 | ]
704 | }
705 | ],
706 | "metadata": {
707 | "kernelspec": {
708 | "display_name": "Python 3",
709 | "language": "python",
710 | "name": "python3"
711 | },
712 | "language_info": {
713 | "codemirror_mode": {
714 | "name": "ipython",
715 | "version": 3
716 | },
717 | "file_extension": ".py",
718 | "mimetype": "text/x-python",
719 | "name": "python",
720 | "nbconvert_exporter": "python",
721 | "pygments_lexer": "ipython3",
722 | "version": "3.7.0"
723 | }
724 | },
725 | "nbformat": 4,
726 | "nbformat_minor": 1
727 | }
728 |
--------------------------------------------------------------------------------
/notebooks/image/orientation/lbp-based-image-orientation.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "code",
5 | "execution_count": null,
6 | "metadata": {},
7 | "outputs": [],
8 | "source": [
9 | "def joint_difference_distribution(gray_img, center_coordinates, P, R):\n",
10 | " neigborhood = calculate_neighborhood(center_coordinates, P, R)\n",
11 | " f = interpolate2d(gray_img, kind='cubic')\n",
12 | " g_p = calculate_neiborhood_values(neigborhood, f)\n",
13 | " g_c = f(*center_coordinates)\n",
14 | " \n",
15 | " return np.round(g_p - g_c, 15)\n",
16 | "\n",
17 | "def binary_joint_distribution(gray_img, center_coordinates, P, R):\n",
18 | " T = joint_difference_distribution(gray_img, center_coordinates, P, R)\n",
19 | " return np.where(T >= 0, 1, 0)"
20 | ]
21 | },
22 | {
23 | "cell_type": "markdown",
24 | "metadata": {},
25 | "source": [
26 | "### Local Binary Pattern\n",
27 | "\n",
28 | "$LBP_{P,R}$ operater is by definition invariant against any monotonic transformation of the gray scale. As long as the order of the gray values stays the same, the output of the $LBP_{P,R}$ operator remains constant.\n",
29 | "\n",
30 | "$$LBP_{P,R} = \\sum_{p=0}^{P-1} s(g_p - g_c) 2^p$$\n",
31 | "\n",
32 | "where \n",
33 | "\n",
34 | "$$s(x) = \n",
35 | "\\begin{cases} \n",
36 | " 1 & x\\geq0 \\\\\n",
37 | " 0 & x<0\n",
38 | "\\end{cases}\n",
39 | "$$"
40 | ]
41 | },
42 | {
43 | "cell_type": "code",
44 | "execution_count": null,
45 | "metadata": {},
46 | "outputs": [],
47 | "source": [
48 | "def LBP(gray_img, center_coordinates, P, R):\n",
49 | " s = binary_joint_distribution(gray_img, center_coordinates, P, R)\n",
50 | " p = np.arange(0, P)\n",
51 | " binomial_factor = 2 ** p\n",
52 | " return np.sum(binomial_factor * s)"
53 | ]
54 | },
55 | {
56 | "cell_type": "markdown",
57 | "metadata": {},
58 | "source": [
59 | "## Conversion RGB a YUV\n",
60 | "\n",
61 | "According to [1], converting from RGB to Y'UV we need the following equations:\n",
62 | "\n",
63 | "$$Y' = W_R R + W_G G + W_b B$$\n",
64 | "\n",
65 | "$$U = U_{max} \\frac{B - Y'}{1 - W_B}$$\n",
66 | "\n",
67 | "$$V = V_{max} \\frac{R - Y'}{1 - W_R}$$\n",
68 | "\n",
69 | "$$W_R = 0.299;\\hspace{0.5em}W_G = 1 - W_R - W_B;\\hspace{0.5em}W_B = 0.114;\\hspace{0.5em}U_{max} = 0.436;\\hspace{0.5em}V_{max} = 0.615$$\n",
70 | "\n",
71 | "where R, G, B are the matrix representation of red, green and blue channels. The previous equations, can be represented as a matrix multiplication\n",
72 | "\n",
73 | "$$\n",
74 | "\\begin{bmatrix}\n",
75 | " Y' \\\\\n",
76 | " U \\\\\n",
77 | " V\n",
78 | "\\end{bmatrix} =\n",
79 | "\\begin{bmatrix}\n",
80 | " 0.299 & 0.587 & 1.114 & \\\\\n",
81 | " -0.14713 & -0.28886 & 0.436 \\\\\n",
82 | " 0.615 & -0.51499 & -0.10001\n",
83 | "\\end{bmatrix}\n",
84 | "\\begin{bmatrix}\n",
85 | " R \\\\\n",
86 | " G \\\\\n",
87 | " B\n",
88 | "\\end{bmatrix}\n",
89 | "$$\n",
90 | "\n",
91 | "*Hint: I took more precise weights from [2]"
92 | ]
93 | },
94 | {
95 | "cell_type": "code",
96 | "execution_count": null,
97 | "metadata": {},
98 | "outputs": [],
99 | "source": [
100 | "def rgb2yuv(rgb):\n",
101 | " error_message = 'The image must be RBG'\n",
102 | " assert len(rgb.shape)== 3, error_message\n",
103 | " assert rgb.shape[-1] == 3, error_message\n",
104 | " \n",
105 | " W = np.array([\n",
106 | " [ 0.299 , 0.587 , 0.114 ],\n",
107 | " [-0.14714119, -0.28886916, 0.43601035 ],\n",
108 | " [ 0.61497538, -0.51496512, -0.10001026 ]\n",
109 | " ])\n",
110 | " \n",
111 | " return rgb @ W.T"
112 | ]
113 | },
114 | {
115 | "cell_type": "markdown",
116 | "metadata": {},
117 | "source": [
118 | "# Color Moments\n",
119 | "\n",
120 | "### Mean\n",
121 | "$$\\mu_i = \\frac{1}{N} \\sum_{j=1}^N p_{ij}$$\n",
122 | "\n",
123 | "where *N* is the number of pixes in the image and $p_{ij}$ is the value of the j-th pixel of the i-th color channel. \n",
124 | "\n",
125 | "### Standard Deviation\n",
126 | "\n",
127 | "$$\\sigma_i = \\sqrt{\\frac{1}{N} \\sum_{j=1}^N (p_{ij} - \\mu_i) ^ 2}$$\n",
128 | "\n",
129 | "where $\\mu_i$ is the mean of the i-th color channel."
130 | ]
131 | },
132 | {
133 | "cell_type": "code",
134 | "execution_count": null,
135 | "metadata": {},
136 | "outputs": [],
137 | "source": [
138 | "def color_moment(image, order=1):\n",
139 | " dim = image.ndim\n",
140 | " axis = tuple([i for i in range(img.ndim - 1)])\n",
141 | " \n",
142 | " if order == 1:\n",
143 | " return np.mean(image, axis=axis)\n",
144 | " if order == 2:\n",
145 | " return np.std(image, axis=axis)\n",
146 | " else:\n",
147 | " raise ValueError('Order should be 1 for mean or 2 for std')"
148 | ]
149 | },
150 | {
151 | "cell_type": "markdown",
152 | "metadata": {},
153 | "source": [
154 | "## Auxiliary Functions"
155 | ]
156 | },
157 | {
158 | "cell_type": "code",
159 | "execution_count": null,
160 | "metadata": {},
161 | "outputs": [],
162 | "source": [
163 | "def load_image(url, as_gray=False):\n",
164 | " image_stream = request.urlopen(url)\n",
165 | " return skimage.io.imread(image_stream, as_gray=as_gray, plugin='pil')\n",
166 | "\n",
167 | "import skimage.color\n",
168 | "\n",
169 | "url = 'https://www.propertyfinder.ae/property/9607847b4ffe15366c4cae076dafb4f3/668/452/MODE/e71028/5993980-3b974o.webp'\n",
170 | "img = load_image(url, False)\n",
171 | "img_rgb = skimage.color.rgba2rgb(img)"
172 | ]
173 | },
174 | {
175 | "cell_type": "code",
176 | "execution_count": null,
177 | "metadata": {},
178 | "outputs": [],
179 | "source": [
180 | "axis = tuple([i for i in range(img.ndim - 1)])\n",
181 | "np.mean(img, axis=axis)"
182 | ]
183 | },
184 | {
185 | "cell_type": "code",
186 | "execution_count": null,
187 | "metadata": {},
188 | "outputs": [],
189 | "source": [
190 | "color_moment(img_rgb, order=1)"
191 | ]
192 | },
193 | {
194 | "cell_type": "code",
195 | "execution_count": null,
196 | "metadata": {},
197 | "outputs": [],
198 | "source": [
199 | "rgb2yuv(img_rgb)"
200 | ]
201 | },
202 | {
203 | "cell_type": "code",
204 | "execution_count": null,
205 | "metadata": {},
206 | "outputs": [],
207 | "source": [
208 | "gray_img = skimage.color.rgb2gray(img_rgb)\n",
209 | "\n",
210 | "R = 1\n",
211 | "P = 4\n",
212 | "center_coordinates = [300, 300]\n",
213 | "\n",
214 | "print(binary_joint_distribution(gray_img, center_coordinates, P, R))\n",
215 | "print(LBP(gray_img, center_coordinates, P, R))"
216 | ]
217 | },
218 | {
219 | "cell_type": "markdown",
220 | "metadata": {},
221 | "source": [
222 | "[1] https://www.itu.int/dms_pubrec/itu-r/rec/bt/R-REC-BT.601-7-201103-I!!PDF-E.pdf\n",
223 | "\n",
224 | "[2] https://github.com/scikit-image/scikit-image/blob/master/skimage/color/colorconv.py#L384"
225 | ]
226 | }
227 | ],
228 | "metadata": {
229 | "kernelspec": {
230 | "display_name": "Python 3",
231 | "language": "python",
232 | "name": "python3"
233 | },
234 | "language_info": {
235 | "codemirror_mode": {
236 | "name": "ipython",
237 | "version": 3
238 | },
239 | "file_extension": ".py",
240 | "mimetype": "text/x-python",
241 | "name": "python",
242 | "nbconvert_exporter": "python",
243 | "pygments_lexer": "ipython3",
244 | "version": "3.7.0"
245 | }
246 | },
247 | "nbformat": 4,
248 | "nbformat_minor": 2
249 | }
250 |
--------------------------------------------------------------------------------
/notebooks/image/quality/brisque.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "code",
5 | "execution_count": null,
6 | "metadata": {
7 | "pycharm": {
8 | "is_executing": false
9 | }
10 | },
11 | "outputs": [],
12 | "source": [
13 | "!pip install opencv-python>=3.4.2.17\n",
14 | "!pip install libsvm>=3.23.0"
15 | ]
16 | },
17 | {
18 | "cell_type": "code",
19 | "execution_count": null,
20 | "metadata": {
21 | "pycharm": {
22 | "is_executing": false
23 | }
24 | },
25 | "outputs": [],
26 | "source": [
27 | "import collections\n",
28 | "from itertools import chain\n",
29 | "import urllib.request as request\n",
30 | "import pickle \n",
31 | "\n",
32 | "import numpy as np\n",
33 | "\n",
34 | "import scipy.signal as signal\n",
35 | "import scipy.special as special\n",
36 | "import scipy.optimize as optimize\n",
37 | "\n",
38 | "import matplotlib.pyplot as plt\n",
39 | "\n",
40 | "import skimage.io\n",
41 | "import skimage.transform\n",
42 | "\n",
43 | "import cv2\n",
44 | "\n",
45 | "from libsvm import svmutil"
46 | ]
47 | },
48 | {
49 | "cell_type": "markdown",
50 | "metadata": {},
51 | "source": [
52 | "# Image Quality Assessment\n",
53 | "\n",
54 | "Image quality is a notion that highly depends on observers. Generally, \n",
55 | "it is linked to the conditions in which it is viewed; therefore, a highly subjective topic. Image quality assessment aims to quantitatively represent the human perception of quality. These metrics commonly are used to analyze the performance of algorithms in different fields of computer vision like image compression, image transmission, and image processing [1].\n",
56 | "\n",
57 | "Image quality assessment (IQA) is mainly divided into two areas of research (1) reference-based evaluation and (2) no-reference evaluation. The main difference is that reference-based methods depend on a high-quality image as a source to evaluate the difference between images. An example of reference-based evaluations is the Structural Similarity Index (SSIM) [2].\n",
58 | "\n",
59 | "## No-reference Image Quality Assessment\n",
60 | "\n",
61 | "No-reference image quality assessment does not require a base image to evaluate an image quality, the only information that the algorithm receives is the distorted image whose quality is being assessed.\n",
62 | "\n",
63 | "Blind methods are mostly comprised of two steps. The first step calculates features that describe the image's structure and the second step relates the features with the human opinion of the image quality. TID2008 is a famous database created following a methodology that describes how to measure human opinion scores from referenced images [3], it is widely used to compare the performance of IQA algorithms.\n",
64 | "\n",
65 | "## Blind/referenceless image spatial quality evaluator (BRISQUE)\n",
66 | "\n",
67 | "BRISQUE [4] is a model that only used the image pixels to calculate features (other methods are based on image transformation to other spaces like wavelet or DCT). It is demonstrated to be highly efficient as it does not need any transformation to calculate its features.\n",
68 | "\n",
69 | "It relies on spatial Natural Scene Statistics (NSS) model of locally normalized luminance coefficients in the spatial domain, as well as the model for pairwise products of these coefficients. \n",
70 | "\n",
71 | "## Methodology\n",
72 | "### Natural Scene Statistics in the Spatial Domain\n",
73 | "Given an image $I(i, j)$, first, compute the locally normalized luminances $\\hat{I}(i,j)$ via local mean subtraction $\\mu(i,j)$ and divide it by the local deviation $\\sigma(i, j)$. $C$ is added to avoid zero divisions. \n",
74 | "\n",
75 | "$$\\hat{I}(i,j) = \\frac{I(i,j) - \\mu(i,j)}{\\sigma(i,j) + C}$$\n",
76 | "\n",
77 | "*Hint: If $I(i,j)$'s domain is [0,255] then $C=1$ if the domain is [0,1] then $C=1/255$.* \n",
78 | "\n",
79 | "To calculate the locally normalized luminance, also known as mean substracted contrast normalized (MSCN) coefficients, first, we need to calculate the local mean\n",
80 | "\n",
81 | "$$\\mu(i,j) = \\sum_{k=-K}^{K}\\sum_{l=-L}^{L}w_{k,l}I_{k,l}(i,j)$$\n",
82 | "\n",
83 | "where $w$ is a Gaussian kernel of size (K, L).\n",
84 | "\n",
85 | "The way that the author displays the local mean could be a little bit confusing but it is just applying a Gaussian filter to the image."
86 | ]
87 | },
88 | {
89 | "cell_type": "code",
90 | "execution_count": null,
91 | "metadata": {
92 | "pycharm": {
93 | "is_executing": false
94 | }
95 | },
96 | "outputs": [],
97 | "source": [
98 | "def normalize_kernel(kernel):\n",
99 | " return kernel / np.sum(kernel)\n",
100 | "\n",
101 | "def gaussian_kernel2d(n, sigma):\n",
102 | " Y, X = np.indices((n, n)) - int(n/2)\n",
103 | " gaussian_kernel = 1 / (2 * np.pi * sigma ** 2) * np.exp(-(X ** 2 + Y ** 2) / (2 * sigma ** 2)) \n",
104 | " return normalize_kernel(gaussian_kernel)\n",
105 | "\n",
106 | "def local_mean(image, kernel):\n",
107 | " return signal.convolve2d(image, kernel, 'same')"
108 | ]
109 | },
110 | {
111 | "cell_type": "markdown",
112 | "metadata": {},
113 | "source": [
114 | "Then, we calculate the local deviation\n",
115 | "\n",
116 | "$$ \\sigma(i,j) = \\sqrt{\\sum_{k=-K}^{K}\\sum_{l=-L}^{L}w_{k,l}(I_{k,l}(i, j) - \\mu(i, j))^2 } $$"
117 | ]
118 | },
119 | {
120 | "cell_type": "code",
121 | "execution_count": null,
122 | "metadata": {
123 | "pycharm": {
124 | "is_executing": false
125 | }
126 | },
127 | "outputs": [],
128 | "source": [
129 | "def local_deviation(image, local_mean, kernel):\n",
130 | " \"Vectorized approximation of local deviation\"\n",
131 | " sigma = image ** 2\n",
132 | " sigma = signal.convolve2d(sigma, kernel, 'same')\n",
133 | " return np.sqrt(np.abs(local_mean ** 2 - sigma))"
134 | ]
135 | },
136 | {
137 | "cell_type": "markdown",
138 | "metadata": {},
139 | "source": [
140 | "Finally, we calculate the MSCN coefficients\n",
141 | "\n",
142 | "$$\\hat{I}(i,j) = \\frac{I(i,j) - \\mu(i,j)}{\\sigma(i,j) + C}$$"
143 | ]
144 | },
145 | {
146 | "cell_type": "code",
147 | "execution_count": null,
148 | "metadata": {
149 | "pycharm": {
150 | "is_executing": false
151 | }
152 | },
153 | "outputs": [],
154 | "source": [
155 | "def calculate_mscn_coefficients(image, kernel_size=6, sigma=7/6):\n",
156 | " C = 1/255\n",
157 | " kernel = gaussian_kernel2d(kernel_size, sigma=sigma)\n",
158 | " local_mean = signal.convolve2d(image, kernel, 'same')\n",
159 | " local_var = local_deviation(image, local_mean, kernel)\n",
160 | " \n",
161 | " return (image - local_mean) / (local_var + C)"
162 | ]
163 | },
164 | {
165 | "cell_type": "markdown",
166 | "metadata": {},
167 | "source": [
168 | "The author found that the MSCN coefficients are distributed as a Generalized Gaussian Distribution (GGD) for a broader spectrum of distorted image.\n",
169 | "\n",
170 | "$$f(x; \\alpha, \\sigma^2) = \\frac{\\alpha}{2\\beta\\Gamma(1/\\alpha)}e^{-\\big(\\frac{|x|}{\\beta}\\big)^\\alpha}$$\n",
171 | "\n",
172 | "where\n",
173 | "\n",
174 | "$$\\beta = \\sigma \\sqrt{\\frac{\\Gamma\\big(\\frac{1}{\\alpha}\\big)}{\\Gamma\\big(\\frac{3}{\\alpha}\\big)}}$$\n",
175 | "\n",
176 | "and $\\Gamma$ is the gamma function.\n",
177 | "\n",
178 | "The shape $\\alpha$ controls the shape and $\\sigma^2$ th variance."
179 | ]
180 | },
181 | {
182 | "cell_type": "code",
183 | "execution_count": null,
184 | "metadata": {
185 | "pycharm": {
186 | "is_executing": false
187 | }
188 | },
189 | "outputs": [],
190 | "source": [
191 | "def generalized_gaussian_dist(x, alpha, sigma):\n",
192 | " beta = sigma * np.sqrt(special.gamma(1 / alpha) / special.gamma(3 / alpha))\n",
193 | " \n",
194 | " coefficient = alpha / (2 * beta() * special.gamma(1 / alpha))\n",
195 | " return coefficient * np.exp(-(np.abs(x) / beta) ** alpha)"
196 | ]
197 | },
198 | {
199 | "cell_type": "markdown",
200 | "metadata": {},
201 | "source": [
202 | "### Pairwise products of neighboring MSCN coefficients\n",
203 | "\n",
204 | "The signs of adjacent coefficients also exhibit a regular structure, which gets disturbed in the presence of distortion. The author proposes the model of pairwise products of neighboring MSCN coefficients along four directions (1) horizontal $H$, (2) vertical $V$, (3) main-diagonal $D1$ and (4) secondary-diagonal $D2$.\n",
205 | "\n",
206 | "$$H(i,j) = \\hat{I}(i,j) \\hat{I}(i, j + 1)$$\n",
207 | "$$V(i,j) = \\hat{I}(i,j) \\hat{I}(i + 1, j)$$\n",
208 | "$$D1(i,j) = \\hat{I}(i,j) \\hat{I}(i + 1, j + 1)$$\n",
209 | "$$D2(i,j) = \\hat{I}(i,j) \\hat{I}(i + 1, j - 1)$$"
210 | ]
211 | },
212 | {
213 | "cell_type": "code",
214 | "execution_count": null,
215 | "metadata": {
216 | "pycharm": {
217 | "is_executing": false
218 | }
219 | },
220 | "outputs": [],
221 | "source": [
222 | "def calculate_pair_product_coefficients(mscn_coefficients):\n",
223 | " return collections.OrderedDict({\n",
224 | " 'mscn': mscn_coefficients,\n",
225 | " 'horizontal': mscn_coefficients[:, :-1] * mscn_coefficients[:, 1:],\n",
226 | " 'vertical': mscn_coefficients[:-1, :] * mscn_coefficients[1:, :],\n",
227 | " 'main_diagonal': mscn_coefficients[:-1, :-1] * mscn_coefficients[1:, 1:],\n",
228 | " 'secondary_diagonal': mscn_coefficients[1:, :-1] * mscn_coefficients[:-1, 1:]\n",
229 | " })"
230 | ]
231 | },
232 | {
233 | "cell_type": "markdown",
234 | "metadata": {},
235 | "source": [
236 | "The author mentions that the Generalized Gaussian Distribution does not provide good fit to the empirical histograms of coefficient producs. Thus, they propose the Asymmetric Generalized Gaussian Distribution (AGGD) model [5].\n",
237 | "\n",
238 | "$$\n",
239 | "f(x; \\nu, \\sigma_l^2, \\sigma_r^2) = \n",
240 | " \\begin{cases} \n",
241 | " \\frac{\\nu}{(\\beta_l + \\beta_r)\\Gamma\\big(\\frac{1}{\\nu}\\big)}e^{\\big(-\\big(\\frac{-x}{\\beta_l}\\big)^\\nu\\big)} & x < 0 \\\\\n",
242 | " \\frac{\\nu}{(\\beta_l + \\beta_r)\\Gamma\\big(\\frac{1}{\\nu}\\big)}e^{\\big(-\\big(\\frac{x}{\\beta_r}\\big)^\\nu\\big)} & x >= 0\n",
243 | "\\end{cases}\n",
244 | "$$\n",
245 | "\n",
246 | "where\n",
247 | "\n",
248 | "$$\\beta_{side} = \\sigma_{side} \\sqrt{\\frac{\\Gamma\\big(\\frac{1}{\\nu}\\big)}{\\Gamma\\big(\\frac{3}{\\nu}\\big)}}$$\n",
249 | "\n",
250 | "and $side$ can be either $r$ or $l$.\n",
251 | "\n",
252 | "Another parameter that is not reflected in the previous formula is the mean\n",
253 | "\n",
254 | "$$\\eta = (\\beta_r - beta_l) \\frac{\\Gamma\\big(\\frac{2}{\\nu}\\big)}{\\Gamma\\big(\\frac{1}{\\nu}\\big)}$$"
255 | ]
256 | },
257 | {
258 | "cell_type": "code",
259 | "execution_count": null,
260 | "metadata": {
261 | "pycharm": {
262 | "is_executing": false
263 | }
264 | },
265 | "outputs": [],
266 | "source": [
267 | "def asymmetric_generalized_gaussian(x, nu, sigma_l, sigma_r):\n",
268 | " def beta(sigma):\n",
269 | " return sigma * np.sqrt(special.gamma(1 / nu) / special.gamma(3 / nu))\n",
270 | " \n",
271 | " coefficient = nu / ((beta(sigma_l) + beta(sigma_r)) * special.gamma(1 / nu))\n",
272 | " f = lambda x, sigma: coefficient * np.exp(-(x / beta(sigma)) ** nu)\n",
273 | " \n",
274 | " return np.where(x < 0, f(-x, sigma_l), f(x, sigma_r))"
275 | ]
276 | },
277 | {
278 | "cell_type": "markdown",
279 | "metadata": {},
280 | "source": [
281 | "### Fitting Asymmetric Generalized Gaussian Distribution\n",
282 | "\n",
283 | "The methodology to fit an Asymmetric Generalized Gaussian Distribution is described in [5].\n",
284 | "\n",
285 | "1. Calculate $\\hat{\\gamma}$ where $N_l$ is the number of negative samples and $N_r$ is the number of positive samples. \n",
286 | "\n",
287 | "$$\n",
288 | "\\hat{\\gamma} = \\frac{\\sqrt{\\frac{1}{N_l - 1}\\sum_{k=1, x_k < 0}^{N_l} x_k^2}\n",
289 | "}{\\sqrt{\\frac{1}{N_r - 1}\\sum_{k=1, x_k >= 0}^{N_r} x_k^2}\n",
290 | "}\n",
291 | "$$\n",
292 | "\n",
293 | "2. Calculate $\\hat{r}$.\n",
294 | "\n",
295 | "$$\\hat{r} = \\frac{\\big(\\frac{\\sum|x_k|}{N_l + N_r}\\big)^2}{\\frac{\\sum{x_k ^ 2}}{N_l + N_r}} $$\n",
296 | "\n",
297 | "3. Calculate $\\hat{R}$ using $\\hat{\\gamma}$ and $\\hat{r}$ estimations.\n",
298 | "\n",
299 | "$$\\hat{R} = \\hat{r} \\frac{(\\hat{\\gamma}^3 + 1)(\\hat{\\gamma} + 1)}{(\\hat{\\gamma}^2 + 1)^2}$$\n",
300 | "\n",
301 | "4. Estimate $\\alpha$ using the approximation of the inverse generalized Gaussian ratio.\n",
302 | "\n",
303 | "$$\\hat{\\alpha} = \\hat{\\rho} ^ {-1}(\\hat{R})$$\n",
304 | "\n",
305 | "$$\\rho(\\alpha) = \\frac{\\Gamma(2 / \\alpha) ^ 2}{\\Gamma(1 / \\alpha) \\Gamma(3 / \\alpha)}$$\n",
306 | "\n",
307 | "5. Estimate left and right scale parameters.\n",
308 | "$$\\sigma_l = \\sqrt{\\frac{1}{N_l - 1}\\sum_{k=1, x_k < 0}^{N_l} x_k^2}$$\n",
309 | "$$\\sigma_r = \\sqrt{\\frac{1}{N_r - 1}\\sum_{k=1, x_k >= 0}^{N_r} x_k^2}$$"
310 | ]
311 | },
312 | {
313 | "cell_type": "code",
314 | "execution_count": null,
315 | "metadata": {
316 | "pycharm": {
317 | "is_executing": false
318 | }
319 | },
320 | "outputs": [],
321 | "source": [
322 | "def asymmetric_generalized_gaussian_fit(x):\n",
323 | " def estimate_phi(alpha):\n",
324 | " numerator = special.gamma(2 / alpha) ** 2\n",
325 | " denominator = special.gamma(1 / alpha) * special.gamma(3 / alpha)\n",
326 | " return numerator / denominator\n",
327 | "\n",
328 | " def estimate_r_hat(x):\n",
329 | " size = np.prod(x.shape)\n",
330 | " return (np.sum(np.abs(x)) / size) ** 2 / (np.sum(x ** 2) / size)\n",
331 | "\n",
332 | " def estimate_R_hat(r_hat, gamma):\n",
333 | " numerator = (gamma ** 3 + 1) * (gamma + 1)\n",
334 | " denominator = (gamma ** 2 + 1) ** 2\n",
335 | " return r_hat * numerator / denominator\n",
336 | "\n",
337 | " def mean_squares_sum(x, filter = lambda z: z == z):\n",
338 | " filtered_values = x[filter(x)]\n",
339 | " squares_sum = np.sum(filtered_values ** 2)\n",
340 | " return squares_sum / ((filtered_values.shape))\n",
341 | "\n",
342 | " def estimate_gamma(x):\n",
343 | " left_squares = mean_squares_sum(x, lambda z: z < 0)\n",
344 | " right_squares = mean_squares_sum(x, lambda z: z >= 0)\n",
345 | "\n",
346 | " return np.sqrt(left_squares) / np.sqrt(right_squares)\n",
347 | "\n",
348 | " def estimate_alpha(x):\n",
349 | " r_hat = estimate_r_hat(x)\n",
350 | " gamma = estimate_gamma(x)\n",
351 | " R_hat = estimate_R_hat(r_hat, gamma)\n",
352 | "\n",
353 | " solution = optimize.root(lambda z: estimate_phi(z) - R_hat, [0.2]).x\n",
354 | "\n",
355 | " return solution[0]\n",
356 | "\n",
357 | " def estimate_sigma(x, alpha, filter = lambda z: z < 0):\n",
358 | " return np.sqrt(mean_squares_sum(x, filter))\n",
359 | " \n",
360 | " def estimate_mean(alpha, sigma_l, sigma_r):\n",
361 | " return (sigma_r - sigma_l) * constant * (special.gamma(2 / alpha) / special.gamma(1 / alpha))\n",
362 | " \n",
363 | " alpha = estimate_alpha(x)\n",
364 | " sigma_l = estimate_sigma(x, alpha, lambda z: z < 0)\n",
365 | " sigma_r = estimate_sigma(x, alpha, lambda z: z >= 0)\n",
366 | " \n",
367 | " constant = np.sqrt(special.gamma(1 / alpha) / special.gamma(3 / alpha))\n",
368 | " mean = estimate_mean(alpha, sigma_l, sigma_r)\n",
369 | " \n",
370 | " return alpha, mean, sigma_l, sigma_r"
371 | ]
372 | },
373 | {
374 | "cell_type": "markdown",
375 | "metadata": {},
376 | "source": [
377 | "### Calculate BRISQUE features\n",
378 | "\n",
379 | "The features needed to calculate the image quality are the result of fitting the MSCN coefficients and shifted products to the Generalized Gaussian Distributions. First, we need to fit the MSCN coefficients to the GDD, then the pairwise products to the AGGD. A summary of the features is the following:\n",
380 | "\n",
381 | "| Feature ID | Feature Description | Computation Procedure |\n",
382 | "|-----------------|------------------------------------------------|----------------------------------|\n",
383 | "| $f_1-f_2$ | Shape and variance | Fit GGD to MSCN coefficients |\n",
384 | "| $f_3-f_6$ | Shape, mean, left variance, right variance | Fit AGGD to H pairwise products |\n",
385 | "| $f_7-f_{10}$ | Shape, mean, left variance, right variance | Fit AGGD to V pairwise products |\n",
386 | "| $f_{11}-f_{14}$ | Shape, mean, left variance, right variance | Fit AGGD to D1 pairwise products |\n",
387 | "| $f_{15}-f_{18}$ | Shape, mean, left variance, right variance | Fit AGGD to D2 pairwise products |"
388 | ]
389 | },
390 | {
391 | "cell_type": "code",
392 | "execution_count": null,
393 | "metadata": {
394 | "pycharm": {
395 | "is_executing": false
396 | }
397 | },
398 | "outputs": [],
399 | "source": [
400 | "def calculate_brisque_features(image, kernel_size=7, sigma=7/6):\n",
401 | " def calculate_features(coefficients_name, coefficients, accum=np.array([])):\n",
402 | " alpha, mean, sigma_l, sigma_r = asymmetric_generalized_gaussian_fit(coefficients)\n",
403 | "\n",
404 | " if coefficients_name == 'mscn':\n",
405 | " var = (sigma_l ** 2 + sigma_r ** 2) / 2\n",
406 | " return [alpha, var]\n",
407 | " \n",
408 | " return [alpha, mean, sigma_l ** 2, sigma_r ** 2]\n",
409 | " \n",
410 | " mscn_coefficients = calculate_mscn_coefficients(image, kernel_size, sigma)\n",
411 | " coefficients = calculate_pair_product_coefficients(mscn_coefficients)\n",
412 | " \n",
413 | " features = [calculate_features(name, coeff) for name, coeff in coefficients.items()]\n",
414 | " flatten_features = list(chain.from_iterable(features))\n",
415 | " return np.array(flatten_features)"
416 | ]
417 | },
418 | {
419 | "cell_type": "markdown",
420 | "metadata": {},
421 | "source": [
422 | "# Hands-on\n",
423 | "\n",
424 | "After creating all the functions needed to calculate the brisque features, we can estimate the image quality for a given image. In [4], they use an image that comes from the Kodak dataset [6]."
425 | ]
426 | },
427 | {
428 | "cell_type": "markdown",
429 | "metadata": {},
430 | "source": [
431 | "## Auxiliary Functions"
432 | ]
433 | },
434 | {
435 | "cell_type": "code",
436 | "execution_count": null,
437 | "metadata": {
438 | "pycharm": {
439 | "is_executing": false
440 | }
441 | },
442 | "outputs": [],
443 | "source": [
444 | "def load_image(url):\n",
445 | " image_stream = request.urlopen(url)\n",
446 | " return skimage.io.imread(image_stream, plugin='pil')\n",
447 | "\n",
448 | "def plot_histogram(x, label):\n",
449 | " n, bins = np.histogram(x.ravel(), bins=50)\n",
450 | " n = n / np.max(n)\n",
451 | " plt.plot(bins[:-1], n, label=label, marker='o')"
452 | ]
453 | },
454 | {
455 | "cell_type": "markdown",
456 | "metadata": {},
457 | "source": [
458 | "## 1. Load image"
459 | ]
460 | },
461 | {
462 | "cell_type": "code",
463 | "execution_count": null,
464 | "metadata": {
465 | "pycharm": {
466 | "is_executing": false
467 | }
468 | },
469 | "outputs": [],
470 | "source": [
471 | "%matplotlib inline\n",
472 | "plt.rcParams[\"figure.figsize\"] = 12, 9\n",
473 | "\n",
474 | "url = 'http://www.cs.albany.edu/~xypan/research/img/Kodak/kodim05.png'\n",
475 | "image = load_image(url)\n",
476 | "gray_image = skimage.color.rgb2gray(image)\n",
477 | "\n",
478 | "_ = skimage.io.imshow(image)"
479 | ]
480 | },
481 | {
482 | "cell_type": "markdown",
483 | "metadata": {},
484 | "source": [
485 | "## 2. Calculate Coefficients"
486 | ]
487 | },
488 | {
489 | "cell_type": "code",
490 | "execution_count": null,
491 | "metadata": {
492 | "pycharm": {
493 | "is_executing": false
494 | }
495 | },
496 | "outputs": [],
497 | "source": [
498 | "%%time \n",
499 | "\n",
500 | "mscn_coefficients = calculate_mscn_coefficients(gray_image, 7, 7/6)\n",
501 | "coefficients = calculate_pair_product_coefficients(mscn_coefficients)"
502 | ]
503 | },
504 | {
505 | "cell_type": "markdown",
506 | "metadata": {},
507 | "source": [
508 | "After calculating the MSCN coefficients and the pairwise products, we can verify that the distributions are in fact different."
509 | ]
510 | },
511 | {
512 | "cell_type": "code",
513 | "execution_count": null,
514 | "metadata": {
515 | "pycharm": {
516 | "is_executing": false
517 | }
518 | },
519 | "outputs": [],
520 | "source": [
521 | "%matplotlib inline\n",
522 | "plt.rcParams[\"figure.figsize\"] = 12, 11\n",
523 | "\n",
524 | "for name, coeff in coefficients.items():\n",
525 | " plot_histogram(coeff.ravel(), name)\n",
526 | "\n",
527 | "plt.axis([-2.5, 2.5, 0, 1.05])\n",
528 | "plt.legend()\n",
529 | "plt.show()"
530 | ]
531 | },
532 | {
533 | "cell_type": "markdown",
534 | "metadata": {},
535 | "source": [
536 | "## 3. Fit Coefficients to Generalized Gaussian Distributions "
537 | ]
538 | },
539 | {
540 | "cell_type": "code",
541 | "execution_count": null,
542 | "metadata": {
543 | "pycharm": {
544 | "is_executing": false
545 | }
546 | },
547 | "outputs": [],
548 | "source": [
549 | "%%time \n",
550 | "\n",
551 | "brisque_features = calculate_brisque_features(gray_image, kernel_size=7, sigma=7/6)"
552 | ]
553 | },
554 | {
555 | "cell_type": "markdown",
556 | "metadata": {},
557 | "source": [
558 | "## 4. Resize Image and Calculate BRISQUE Features"
559 | ]
560 | },
561 | {
562 | "cell_type": "code",
563 | "execution_count": null,
564 | "metadata": {
565 | "pycharm": {
566 | "is_executing": false
567 | }
568 | },
569 | "outputs": [],
570 | "source": [
571 | "%%time\n",
572 | "\n",
573 | "downscaled_image = cv2.resize(gray_image, None, fx=1/2, fy=1/2, interpolation = cv2.INTER_CUBIC)\n",
574 | "downscale_brisque_features = calculate_brisque_features(downscaled_image, kernel_size=7, sigma=7/6)\n",
575 | "\n",
576 | "brisque_features = np.concatenate((brisque_features, downscale_brisque_features))"
577 | ]
578 | },
579 | {
580 | "cell_type": "markdown",
581 | "metadata": {},
582 | "source": [
583 | "## 5. Scale Features and Feed the SVR\n",
584 | "The author provides a pretrained SVR model to calculate the quality assessment. However, in order to have good results, we need to scale the features to [-1, 1]. For the latter, we need the same parameters the author used to scale the features vector."
585 | ]
586 | },
587 | {
588 | "cell_type": "code",
589 | "execution_count": null,
590 | "metadata": {
591 | "pycharm": {
592 | "is_executing": false
593 | }
594 | },
595 | "outputs": [],
596 | "source": [
597 | "def scale_features(features):\n",
598 | " with open('normalize.pickle', 'rb') as handle:\n",
599 | " scale_params = pickle.load(handle)\n",
600 | " \n",
601 | " min_ = np.array(scale_params['min_'])\n",
602 | " max_ = np.array(scale_params['max_'])\n",
603 | " \n",
604 | " return -1 + (2.0 / (max_ - min_) * (features - min_))\n",
605 | "\n",
606 | "def calculate_image_quality_score(brisque_features):\n",
607 | " model = svmutil.svm_load_model('brisque_svm.txt')\n",
608 | " scaled_brisque_features = scale_features(brisque_features)\n",
609 | " \n",
610 | " x, idx = svmutil.gen_svm_nodearray(\n",
611 | " scaled_brisque_features,\n",
612 | " isKernel=(model.param.kernel_type == svmutil.PRECOMPUTED))\n",
613 | " \n",
614 | " nr_classifier = 1\n",
615 | " prob_estimates = (svmutil.c_double * nr_classifier)()\n",
616 | " \n",
617 | " return svmutil.libsvm.svm_predict_probability(model, x, prob_estimates)"
618 | ]
619 | },
620 | {
621 | "cell_type": "markdown",
622 | "metadata": {},
623 | "source": [
624 | "The scaled used to represent image quality goes from 0 to 100. An image quality of 100 means that the image's quality is very bad. In the case of the analyzed image, we get that it is a good quality image. It makes sense because we are using the reference image."
625 | ]
626 | },
627 | {
628 | "cell_type": "code",
629 | "execution_count": null,
630 | "metadata": {
631 | "pycharm": {
632 | "is_executing": false
633 | }
634 | },
635 | "outputs": [],
636 | "source": [
637 | "%%time\n",
638 | "\n",
639 | "calculate_image_quality_score(brisque_features)"
640 | ]
641 | },
642 | {
643 | "cell_type": "markdown",
644 | "metadata": {},
645 | "source": [
646 | "## Conclusion\n",
647 | "\n",
648 | "This method was tested with the TID2008 database and performs well; even compared with referenced IQA methods. Although, the future work is to check the performance of other machine learning algorithms like XGBoost, LightGBM, for the pattern recognition step.\n",
649 | "\n",
650 | "## References\n",
651 | "\n",
652 | "[1] Maître, H. (2017). From Photon to pixel: the digital camera handbook. John Wiley & Sons.\n",
653 | "\n",
654 | "[2] Wang, Z., Bovik, A. C., Sheikh, H. R., & Simoncelli, E. P. (2004). Image quality assessment: from error visibility to structural similarity. IEEE transactions on image processing, 13(4), 600-612.\n",
655 | "\n",
656 | "[3] Ponomarenko, N., Lukin, V., Zelensky, A., Egiazarian, K., Carli, M., & Battisti, F. (2009). TID2008-a database for evaluation of full-reference visual quality assessment metrics. Advances of Modern Radioelectronics, 10(4), 30-45.\n",
657 | "\n",
658 | "[4] Mittal, A., Moorthy, A. K., & Bovik, A. C. (2012). No-reference image quality assessment in the spatial domain. IEEE Transactions on Image Processing, 21(12), 4695-4708.\n",
659 | "\n",
660 | "[5] Lasmar, N. E., Stitou, Y., & Berthoumieu, Y. (2009). Multiscale skewed heavy-tailed model for texture analysis. Proceedings - International Conference on Image Processing, ICIP, (1), 2281–2284."
661 | ]
662 | }
663 | ],
664 | "metadata": {
665 | "kernelspec": {
666 | "display_name": "Python 3",
667 | "language": "python",
668 | "name": "python3"
669 | },
670 | "language_info": {
671 | "codemirror_mode": {
672 | "name": "ipython",
673 | "version": 3
674 | },
675 | "file_extension": ".py",
676 | "mimetype": "text/x-python",
677 | "name": "python",
678 | "nbconvert_exporter": "python",
679 | "pygments_lexer": "ipython3",
680 | "version": "3.7.6"
681 | },
682 | "pycharm": {
683 | "stem_cell": {
684 | "cell_type": "raw",
685 | "metadata": {
686 | "collapsed": false
687 | },
688 | "source": []
689 | }
690 | }
691 | },
692 | "nbformat": 4,
693 | "nbformat_minor": 2
694 | }
695 |
--------------------------------------------------------------------------------
/notebooks/image/quality/hosa.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [],
3 | "metadata": {
4 | "kernelspec": {
5 | "display_name": "Python 3",
6 | "language": "python",
7 | "name": "python3"
8 | },
9 | "language_info": {
10 | "codemirror_mode": {
11 | "name": "ipython",
12 | "version": 3
13 | },
14 | "file_extension": ".py",
15 | "mimetype": "text/x-python",
16 | "name": "python",
17 | "nbconvert_exporter": "python",
18 | "pygments_lexer": "ipython3",
19 | "version": "3.7.3"
20 | },
21 | "pycharm": {
22 | "stem_cell": {
23 | "cell_type": "raw",
24 | "metadata": {
25 | "collapsed": false
26 | },
27 | "source": []
28 | }
29 | }
30 | },
31 | "nbformat": 4,
32 | "nbformat_minor": 2
33 | }
34 |
--------------------------------------------------------------------------------
/notebooks/image/quality/live-dataset.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "### MATLAB mat files\n",
8 | "The file `dmos.mat` has two arrays of length 982 each: dmos and orgs. `orgs(i)==0` for distorted images.\n",
9 | "The arrays `dmos` and `orgs` are arranged by concatenating the dmos (and orgs) variables for each database as follows:\n",
10 | "\n",
11 | "```dmos=[dmos_jpeg2000(1:227) dmos_jpeg(1:233) white_noise(1:174) gaussian_blur(1:174) fast_fading(1:174)]```\n",
12 | " \n",
13 | "where `dmos_distortion(i)` is the dmos value for image `distortion/img_i.bmp` where distortion can be one of the five\n",
14 | "described above. \n",
15 | "\n",
16 | "The values of dmos when corresponding `orgs==1` are zero (they are reference images). Note that imperceptible\n",
17 | "loss of quality does not necessarily mean a dmos value of zero due to the nature of the score processing used.\n",
18 | "\n",
19 | "The file refnames_all.mat contains a cell array refnames_all. Entry refnames_all{i} is the name of\n",
20 | "the reference image for image i whose dmos value is given by dmos(i). If orgs(i)==0, then this is a valid"
21 | ]
22 | },
23 | {
24 | "cell_type": "code",
25 | "execution_count": null,
26 | "metadata": {
27 | "pycharm": {
28 | "is_executing": false,
29 | "name": "#%%\n"
30 | }
31 | },
32 | "outputs": [],
33 | "source": [
34 | "import os\n",
35 | "import re\n",
36 | "from enum import unique, IntEnum\n",
37 | "\n",
38 | "import numpy\n",
39 | "import pandas\n",
40 | "from scipy.io import loadmat\n"
41 | ]
42 | },
43 | {
44 | "cell_type": "code",
45 | "execution_count": null,
46 | "metadata": {
47 | "pycharm": {
48 | "is_executing": false,
49 | "name": "#%%\n"
50 | }
51 | },
52 | "outputs": [],
53 | "source": [
54 | "paths = list(os.walk('/home/rocampo/data/live'))\n",
55 | "files = {\n",
56 | " os.path.basename(path): [os.path.join(os.path.basename(path), file) for file in files if '.bmp' in file]\n",
57 | " for path, _, files in paths\n",
58 | " if len(list(filter(lambda x: '.bmp' in x, files))) > 0\n",
59 | "}\n"
60 | ]
61 | },
62 | {
63 | "cell_type": "code",
64 | "execution_count": null,
65 | "metadata": {
66 | "pycharm": {
67 | "is_executing": false,
68 | "name": "#%%\n"
69 | }
70 | },
71 | "outputs": [],
72 | "source": [
73 | "refnames_mat = loadmat('/home/rocampo/data/live/refnames_all.mat')\n",
74 | "dmos_mat = loadmat('/home/rocampo/data/live/dmos.mat')\n",
75 | "dmos_realigned_mat = loadmat('/home/rocampo/data/live/dmos_realigned.mat')\n",
76 | "\n"
77 | ]
78 | },
79 | {
80 | "cell_type": "code",
81 | "execution_count": null,
82 | "metadata": {
83 | "pycharm": {
84 | "is_executing": false,
85 | "name": "#%%\n"
86 | }
87 | },
88 | "outputs": [],
89 | "source": [
90 | "refnames = numpy.hstack(refnames_mat['refnames_all'][0])\n",
91 | "dmos = numpy.hstack(dmos_mat['dmos'])\n",
92 | "dmos_realigned = numpy.hstack(dmos_realigned_mat['dmos_new'])\n",
93 | "dmos_realigned_std = numpy.hstack(dmos_realigned_mat['dmos_std'])\n",
94 | "\n"
95 | ]
96 | },
97 | {
98 | "cell_type": "code",
99 | "execution_count": null,
100 | "metadata": {
101 | "pycharm": {
102 | "is_executing": false,
103 | "name": "#%%\n"
104 | }
105 | },
106 | "outputs": [],
107 | "source": [
108 | "def extract_index(file_name):\n",
109 | " return int(re.findall(r'\\d+', file_name)[-1])\n",
110 | "\n",
111 | "def create_array(file_names):\n",
112 | " return {extract_index(file_name): file_name for file_name in file_names}"
113 | ]
114 | },
115 | {
116 | "cell_type": "code",
117 | "execution_count": null,
118 | "metadata": {
119 | "pycharm": {
120 | "is_executing": false,
121 | "name": "#%%\n"
122 | }
123 | },
124 | "outputs": [],
125 | "source": [
126 | "@unique\n",
127 | "class Distortion(IntEnum):\n",
128 | " jpeg_2000 = 1\n",
129 | " jpeg = 2\n",
130 | " white_noise = 3\n",
131 | " gaussian_blur = 4\n",
132 | " fast_fading = 5\n",
133 | "\n",
134 | "arrays = {\n",
135 | " Distortion.jpeg_2000: create_array(files['jp2k']),\n",
136 | " Distortion.jpeg: create_array(files['jpeg']),\n",
137 | " Distortion.white_noise: create_array(files['wn']),\n",
138 | " Distortion.gaussian_blur: create_array(files['gblur']),\n",
139 | " Distortion.fast_fading: create_array(files['fastfading']), \n",
140 | "}"
141 | ]
142 | },
143 | {
144 | "cell_type": "code",
145 | "execution_count": null,
146 | "metadata": {
147 | "pycharm": {
148 | "is_executing": false,
149 | "name": "#%%\n"
150 | }
151 | },
152 | "outputs": [],
153 | "source": [
154 | "dataframes = [\n",
155 | " pandas.DataFrame({\n",
156 | " 'distortion': distortion, \n",
157 | " 'index': list(paths.keys()),\n",
158 | " 'distorted_path': list(paths.values())\n",
159 | " })\n",
160 | " for distortion, paths in arrays.items() \n",
161 | "]\n",
162 | "\n",
163 | "dataframe = pandas.concat(dataframes)"
164 | ]
165 | },
166 | {
167 | "cell_type": "code",
168 | "execution_count": null,
169 | "metadata": {
170 | "pycharm": {
171 | "is_executing": false,
172 | "name": "#%%\n"
173 | }
174 | },
175 | "outputs": [],
176 | "source": [
177 | "dataframe = dataframe.sort_values(by=['distortion', 'index'])"
178 | ]
179 | },
180 | {
181 | "cell_type": "code",
182 | "execution_count": null,
183 | "metadata": {
184 | "pycharm": {
185 | "is_executing": false,
186 | "name": "#%%\n"
187 | }
188 | },
189 | "outputs": [],
190 | "source": [
191 | "dataframe['reference_path'] = refnames\n",
192 | "dataframe['dmos'] = dmos\n",
193 | "dataframe['dmos_realigned'] = dmos_realigned\n",
194 | "dataframe['dmos_realigned_std'] = dmos_realigned_std\n",
195 | "dataframe.reference_path = 'refimgs/' + dataframe.reference_path\n",
196 | "dataframe.distortion = dataframe.distortion.apply(lambda x: Distortion(x).name)"
197 | ]
198 | },
199 | {
200 | "cell_type": "code",
201 | "execution_count": null,
202 | "metadata": {
203 | "pycharm": {
204 | "is_executing": false,
205 | "name": "#%%\n"
206 | }
207 | },
208 | "outputs": [],
209 | "source": [
210 | "dataframe.to_csv('/home/rocampo/data/live_metadata.csv', index=False)\n",
211 | "\n"
212 | ]
213 | }
214 | ],
215 | "metadata": {
216 | "kernelspec": {
217 | "display_name": "Python 3",
218 | "language": "python",
219 | "name": "python3"
220 | },
221 | "language_info": {
222 | "codemirror_mode": {
223 | "name": "ipython",
224 | "version": 3
225 | },
226 | "file_extension": ".py",
227 | "mimetype": "text/x-python",
228 | "name": "python",
229 | "nbconvert_exporter": "python",
230 | "pygments_lexer": "ipython3",
231 | "version": "3.7.4"
232 | },
233 | "pycharm": {
234 | "stem_cell": {
235 | "cell_type": "raw",
236 | "metadata": {
237 | "collapsed": false
238 | },
239 | "source": []
240 | }
241 | }
242 | },
243 | "nbformat": 4,
244 | "nbformat_minor": 2
245 | }
246 |
--------------------------------------------------------------------------------
/notebooks/image/quality/normalize.pickle:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ocampor/notebooks/76ed27efd36fd481d481980e12f1bab3b5d794df/notebooks/image/quality/normalize.pickle
--------------------------------------------------------------------------------
/notebooks/recommender-system/light-fm.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "code",
5 | "execution_count": null,
6 | "metadata": {},
7 | "outputs": [],
8 | "source": [
9 | "!pip3 install lightfm --user"
10 | ]
11 | },
12 | {
13 | "cell_type": "code",
14 | "execution_count": null,
15 | "metadata": {},
16 | "outputs": [],
17 | "source": [
18 | "import lightfm.datasets as datasets"
19 | ]
20 | },
21 | {
22 | "cell_type": "code",
23 | "execution_count": null,
24 | "metadata": {},
25 | "outputs": [],
26 | "source": [
27 | "import numpy"
28 | ]
29 | },
30 | {
31 | "cell_type": "code",
32 | "execution_count": null,
33 | "metadata": {},
34 | "outputs": [],
35 | "source": [
36 | "data = datasets.fetch_stackexchange(\n",
37 | " 'crossvalidated',\n",
38 | " test_set_fraction=0.1,\n",
39 | " indicator_features=False,\n",
40 | " tag_features=True)"
41 | ]
42 | },
43 | {
44 | "cell_type": "code",
45 | "execution_count": null,
46 | "metadata": {},
47 | "outputs": [],
48 | "source": [
49 | "numpy.histogram(data['item_features'].toarray()[:3])"
50 | ]
51 | },
52 | {
53 | "cell_type": "code",
54 | "execution_count": null,
55 | "metadata": {},
56 | "outputs": [],
57 | "source": [
58 | "data['test'].toarray().shape"
59 | ]
60 | }
61 | ],
62 | "metadata": {
63 | "kernelspec": {
64 | "display_name": "Python 3",
65 | "language": "python",
66 | "name": "python3"
67 | },
68 | "language_info": {
69 | "codemirror_mode": {
70 | "name": "ipython",
71 | "version": 3
72 | },
73 | "file_extension": ".py",
74 | "mimetype": "text/x-python",
75 | "name": "python",
76 | "nbconvert_exporter": "python",
77 | "pygments_lexer": "ipython3",
78 | "version": "3.7.1"
79 | }
80 | },
81 | "nbformat": 4,
82 | "nbformat_minor": 2
83 | }
84 |
--------------------------------------------------------------------------------
/requirements/requirements.dev.txt:
--------------------------------------------------------------------------------
1 | -r requirements.txt
2 |
3 | pytest==5.4.1
4 | nbval==0.9.5
5 |
--------------------------------------------------------------------------------
/requirements/requirements.txt:
--------------------------------------------------------------------------------
1 | jupyter==1.0.0
2 | numpy>=1.15.1
3 | pandas>=0.25.0
4 | scipy>=1.1.0
5 |
6 | #Charts
7 | matplotlib>=2.2.3
8 |
9 | # Machine learning
10 | scikit-image>=0.14.0
11 | scikit-learn>=0.21.3
12 |
13 | # Image
14 | imageio==2.8.0
15 | opencv-python==3.4.2.17
16 | image-quality>=1.0.0
17 | libsvm>=3.23.0
18 |
--------------------------------------------------------------------------------