├── .gitignore
├── CONTRIBUTING.md
├── LICENSE
├── README.md
├── doLCE
├── Makefile
├── README
├── frameCropper.c
├── imageHandling.c
├── imageHandling.h
├── imageProcessing.c
├── imageProcessing.h
├── interpolationStudy.c
└── lenticularFilmColorReconstruction.c
└── lenticular
├── Makefile
├── README.md
├── frameCropper.c
├── imageHandling.c
├── imageHandling.h
├── imageProcessing.c
├── imageProcessing.h
├── interpolationStudy.c
├── lenticular.1
└── lenticular.c
/.gitignore:
--------------------------------------------------------------------------------
1 | .git
2 | *.o
3 | .DS_Store
4 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributions are very welcome!
2 |
3 | Please:
4 |
5 | - keep the [issue tracker](http://github.com/amiaopensource/lenticular/issues) limited to bug reports and feature requests;
6 | - use the [pull requests](http://github.com/amiaopensource/lenticular/pulls) to submit patches to both the code and its documentation.
7 |
8 | Thank you!
9 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Digital Restoration of Lenticular Colours from Greyscale Digitisations
2 |
3 | This piece of software restores the colours from digitisations of lenticular movie films (like Kodacolor or Agfacolor). Of course, the films must have been shot with the RBG filter applied on the camera’s lens, but the digitisation is made without the filter, generating regular greyscale images.
4 |
5 | This repository contains:
6 |
7 | - the original [doLCE](doLCE/README) source code by Joakim Reuteler (2012)
8 | - a [work-in-progress](lenticular/README.md) source code (2018)
9 |
10 | ---
11 |
12 | ## Original doLCE Source Code
13 |
14 | [doLCE](doLCE/README) – do Lenticular film Color rEconstruction
15 |
16 | Copyright (c) 2012 Joakim Reuteler
17 |
18 | This program is free software: you can redistribute it and/or modify it under the terms of the [GNU General Public License](https://www.gnu.org/licenses/#GPL) version 3 as published by the Free Software Foundation.
19 |
20 | ### Bibliography
21 |
22 | Joakim Reuteler and Rudolf Gschwind ([Digital Humanities Lab](http://dhlab.unibas.ch/dolce/), University of Basel, Switzerland): «Die Farben des Riffelfilms. Digitale Farbrekonstruktion von Linsenrasterfilm», in: _Rundbrief Fotografie_, May 2014
23 |
24 | ---
25 |
26 | ## Work-in-Progress Source Code
27 |
28 | An alpha of a modified code, named [lenticular](lenticular/README.md), is available for testing purpose. And contributions are very welcome!
29 |
30 | ### Copyright, Licence and Disclaimer
31 |
32 | Copyright (c) 2012 Joakim Reuteler
33 | Copyright (c) 2018 AMIA Open Source
34 |
35 | The program is released under a [GNU GPL v3](https://www.gnu.org/licenses/gpl-3.0.en.html) Licence and the documentation is released under a [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) Licence.
36 |
37 | This work is provided «as is» without warranty or support of any kind.
38 |
--------------------------------------------------------------------------------
/doLCE/Makefile:
--------------------------------------------------------------------------------
1 | CC=gcc
2 |
3 | CFLAGS=-Wall
4 |
5 | doLCE: lenticularFilmColorReconstruction.o imageHandling.o imageProcessing.o
6 | cc -ltiff lenticularFilmColorReconstruction.o imageHandling.o imageProcessing.o -o doLCE
7 |
8 | inStudy: interpolationStudy.o imageHandling.o imageProcessing.o
9 | cc -ltiff interpolationStudy.o imageHandling.o imageProcessing.o -o inStudy
10 |
11 | crpFrames: frameCropper.o imageHandling.o imageProcessing.o
12 | cc -ltiff frameCropper.o imageHandling.o imageProcessing.o -o crpFrames
13 |
14 | imageHandling.o: imageHandling.c imageHandling.h
15 | cc -c imageHandling.c
16 |
17 | imageProcessing.o: imageProcessing.c imageProcessing.h
18 | cc -c imageProcessing.c
19 |
20 | clean:
21 | rm imageHandling.o lenticularFilmColorReconstruction.o imageProcessing.o doLCE
22 | # rm interpolationStudy.o inStudy
23 | rm frameCropper.o crpFrames
24 |
25 |
--------------------------------------------------------------------------------
/doLCE/README:
--------------------------------------------------------------------------------
1 | doLCE - do Lenticular film Color rEconstruction -
2 | Copyright (C) 2012 Joakim Reuteler
3 |
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License version 3 as
6 | published by the Free Software Foundation.
7 |
8 | This program is distributed in the hope that it will be useful,
9 | but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | GNU General Public License for more details.
12 |
13 | You should have received a copy of the GNU General Public License
14 | along with this program. If not, see .
15 | _______________________________________________________________________
16 |
17 | Please acknowledge: Joakim Reuteler and Rudolf Gschwind, Digital Humanities
18 | Lab, Uni Basel, Switzerland.
19 | Please cite: J. Reuteler and R. Gschwind, Rundbrief Fotografie, "Die Farben
20 | des Riffelfilms - Digitale Farbrekonstruktion von Linsenrasterfilm" May 2014
21 |
22 | 0. Dependencies
23 | - libtiff-dev (the exact name may depend on your distribution/OS)
24 | Linux: install libtiff-dev using your package manager
25 | Mac: install fink and use it to install libtiff-dev
26 | Windows: install MinGW and use it to install libtiff-dev
27 |
28 | 1. How to install
29 | - 'unzip' the compressed folder, 'cd' into it
30 | - build the program from the shell by running 'make' in that directory
31 | - run the program on the shell by './doLCE'
32 |
33 | 2. intended purpose
34 | - reconstruct color stills from gray level scans of lenticular film material
35 | (Kodacolor, ...)
36 |
37 | 3. ideas of software (concept):
38 | 0. No additional comments, aim is to have the code itself understandable
39 | 1. new_...() only allocates memory, values are not set
40 | 2. new_..() operates only if data containing arrays point to NULL
41 | 3. delete_...() releases memory and sets pointers on data containing
42 | fields to NULL
43 | 4. methods do not allocate or release memory (reentrance safe?)
44 | 5. pixel coordinates are ordered as in mathematics: x,y
45 | 6. using a memState_objectXY variable to keep track of allocation and
46 | freeing memory in the main() is advised!
47 | 7. return value 0 <-> OK, other <-> ERROR
48 | 8. methods only report in case of problems, they are quiet in case of
49 | success (main() shall decide when to report success)
50 |
51 | 4. Remarks
52 | 1. The concept of the code is based on the one used for the "Monolith 2"
53 | project conducted IML, University of Basel. However, the "doLCE" code
54 | was rewritten from scratch. In particular the order of the pixel
55 | coordinates in Monolith 2 code is y, x.
56 | 2. The program is in an experimental state, there are hard coded
57 | parameters, such as the default number of pixels making up one
58 | lenticular lens, see line 114 in
59 | "lenticularFilmColorReconstruction.c":
60 | float subPixelPrecisionRasterSpacing = 19.2;
61 | Set this number to a value that fits the resolution of your scans.
62 |
--------------------------------------------------------------------------------
/doLCE/frameCropper.c:
--------------------------------------------------------------------------------
1 | //
2 | // doLCE - do Lenticular film Color rEconstruction -
3 | // Copyright (C) 2012 Joakim Reuteler
4 |
5 | // This program is free software: you can redistribute it and/or modify
6 | // it under the terms of the GNU General Public License as published by
7 | // the Free Software Foundation, either version 3 of the License.
8 |
9 | // This program is distributed in the hope that it will be useful,
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | // GNU General Public License for more details.
13 |
14 | // You should have received a copy of the GNU General Public License
15 | // along with this program. If not, see .
16 | // _______________________________________________________________________
17 |
18 |
19 |
20 | #include "imageHandling.h"
21 | #include "imageProcessing.h"
22 |
23 | #include
24 | #include
25 | #include
26 |
27 |
28 | int main( int argc, char *argv[] ) {
29 | // processing control
30 | int status = 0;
31 |
32 | // constants
33 | char greetingText[128] = "";
34 | sprintf( greetingText, "*\n**\n*** frameCropper - crop center part of rgb frames ***\n**\n* [%s ~ %s]\n\n", __DATE__, __TIME__);
35 | char copyrightText[200] = "This program is free software under the terms of the GNU General Public License version 3.\nSee .\n\n";
36 | char helpText[] = "frameCropper 'width' 'height' 'inputBaseName' 'startNo' 'endNo' 'outputDir'\n";
37 |
38 | char inputImageName[128] = "";
39 | char inputBaseName[128] = "";
40 | char startNoStr[16] = "";
41 | int startNo;
42 | char endNoStr[16] = "";
43 | int endNo;
44 | char outputDirName[128] = "";
45 | char outputImageName[132] = "";
46 |
47 | int frameNo;
48 | char frameNoFormat[8] = "";
49 | char frameNoStr[16] = "";
50 |
51 | // variables
52 | int argNo, optNo;
53 | short spp, bps;
54 | int width, height;
55 | int crpWidth, crpHeight;
56 | int xOffset, yOffset;
57 | int j, i;
58 | int channel;
59 |
60 | // data
61 | rgbImage_t inImg;
62 | inImg.img = NULL;
63 | inImg.memState = 0;
64 | rgbImage_t outImg;
65 | outImg.img = NULL;
66 | outImg.memState = 0;
67 |
68 |
69 | // Plan:
70 | // - read an rgb image, copy only central part with a size of 'crpWidth' x 'crpHeight' and write it to the disk
71 |
72 |
73 | printf( "%s", greetingText );
74 | printf( "%s", copyrightText );
75 |
76 | if ( argc < 7 ) {
77 | status = -1;
78 | printf( "Too few arguments.\n" );
79 | printf( "\n" );
80 | printf( "%s", helpText );
81 | }
82 | else {
83 | argNo = 1;
84 | printf( "argNo = %d\n", argNo );
85 | crpWidth = atoi( argv[argNo] );
86 | crpHeight = atoi( argv[++argNo] );
87 | printf( "crpWidth = %d, crpHeight = %d\n", crpWidth, crpHeight );
88 | strcpy( inputBaseName, argv[++argNo] );
89 | //printf( "inputBaseName = %s\n", inputBaseName );
90 | strcpy( startNoStr, argv[++argNo] );
91 | //printf( "startNoStr = %s\n", startNoStr );
92 | startNo = atoi( argv[argNo] );
93 | //printf( "startNo = %d\n", startNo );
94 | strcpy( endNoStr, argv[++argNo] );
95 | //printf( "endNoStr = %s\n", endNoStr );
96 | endNo = atoi( argv[argNo] );
97 | //printf( "endNo = %d\n", endNo );
98 | strcpy( outputDirName, argv[++argNo] );
99 | //printf( "outputDirName = %s\n", outputDirName );
100 |
101 | printf( "image sequence to be processed : '%s%s.tif' to '%s%s.tif'\n", inputBaseName, startNoStr, inputBaseName, endNoStr );
102 | printf( "cropped frames will be stored as '%s/crp_%s%s.tif' etc.\n", outputDirName, inputBaseName, startNoStr );
103 |
104 | //status = -1;
105 | }
106 |
107 | if ( status == 0 ) {
108 | printf( "\nlog of call : '" );
109 | for ( argNo=0; argNo1 && startNoStr[0]==0 ){
126 | status = -1;
127 | printf( "ERROR: Cannot handle this kind of numbering\n" );
128 | printf( "startNoStr[0] == 0\n" );
129 | printf( "startNoStr == %s\n", startNoStr );
130 | }
131 | else {
132 | sprintf( frameNoFormat, "%%d", strlen(startNoStr) );
133 | //printf( "frameNoFormat = %s\n", frameNoFormat );
134 | }
135 | }
136 | }
137 |
138 | if ( status == 0 ) {
139 | printf( "\n-------------------loop over frames----------------------\n\n" );
140 | //}
141 | for ( frameNo=startNo; frameNo<=endNo && status==0; frameNo++ ) {
142 | sprintf( frameNoStr, frameNoFormat, frameNo );
143 | //printf( "frameNoStr = %s\n", frameNoStr );
144 | sprintf( inputImageName, "%s%s.tif", inputBaseName, frameNoStr );
145 | sprintf( outputImageName, "%s/crp_%s%s.tif", outputDirName, inputBaseName, frameNoStr );
146 | printf( "***************************************************************************\n" );
147 | printf( "*** processing frame %d/%d ('%s')\n", frameNo-startNo+1, endNo-startNo+1, inputImageName );
148 |
149 | if ( status == 0 ) {
150 | printf( "Checking TIFF...\n" );
151 | status = check_TIFF( inputImageName, &spp, &bps, &width, &height );
152 | if ( status == 0 ) {
153 | printf( "> % 5d samples per pixel \n> % 5d bits per sample\n", spp, bps ); // change into "normal" format: blabla = value ?
154 | printf( "> % 5d pixels wide\n> % 5d pixels high\n", width, height );
155 | if ( inImg.memState==1 && (inImg.width!=width || inImg.height!=height) ) {
156 | delete_rgbImage( &inImg );
157 | printf( "inImg.memState = %d\n", inImg.memState );
158 | }
159 | if ( inImg.memState == 0 ) {
160 | status = new_rgbImage( &inImg, width, height );//new_glImage( &glScan, width, height );
161 | printf( "### allocated memory: 'inImg.memState' = %d\n", inImg.memState );
162 | }
163 | if ( inImg.memState == 1 ) {
164 | printf( "Loading TIFF...\n" );
165 | status = read_3x8bitTIFF_rgbImage( inputImageName, &inImg );
166 | //status = read_16bitTIFF_glImage( inputImageName, &glScan );
167 | if ( status == 0 ) {
168 | printf( "> OK.\n" );
169 | }
170 | }
171 | else {
172 | status = -1;
173 | printf( "ERROR: No memory for loading TIFF available.\n" );
174 | }
175 | }
176 | }
177 |
178 | if ( status == 0 ) {
179 | xOffset = (width - crpWidth)/2;
180 | yOffset = (height - crpHeight)/2;
181 | printf( "xOffset = %d, yOffset = %d", xOffset, yOffset );
182 | if ( xOffset>=0 && yOffset>=0 ) {
183 | printf( "Writing result to disk...\n" );
184 | status = writeROI_3x8bitTIFF_rgbImage( &inImg, outputImageName, xOffset, yOffset, crpWidth, crpHeight );
185 | if ( status == 0 ) {
186 | printf( "Stored result to '%s'.\n", outputImageName );
187 | }
188 | }
189 | else {
190 | printf( "Skipping image because it is too small.\n" );
191 | }
192 | }
193 |
194 | printf( "*** done processing frame No %d\n", frameNo );
195 | printf( "***************************************************************************\n\n" );
196 | }
197 | if ( status == 0 ) {
198 | printf( "\n---------------------end loop over frames------------------------\n" );
199 | }
200 | }
201 |
202 | if ( inImg.memState != 0 ) {
203 | printf( "Cleaning up heap...\n" );
204 | delete_rgbImage( &inImg );
205 | printf( "### freed memory 'inImg.memState = %d'\n", inImg.memState );
206 | }
207 | /*
208 | if ( outImg.memState != 0 ) {
209 | delete_rgbImage( &outImg );
210 | printf( "### freed memory 'outImg.memState = %d'\n", inImg.memState );
211 | }
212 | */
213 |
214 | printf( "\nStatus at end : %d\n", status );
215 | return status;
216 | }
217 |
--------------------------------------------------------------------------------
/doLCE/imageHandling.h:
--------------------------------------------------------------------------------
1 | //
2 | // doLCE - do Lenticular film Color rEconstruction -
3 | // Copyright (C) 2012 Joakim Reuteler
4 |
5 | // This program is free software: you can redistribute it and/or modify
6 | // it under the terms of the GNU General Public License version 3 as
7 | // published by the Free Software Foundation.
8 |
9 | // This program is distributed in the hope that it will be useful,
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | // GNU General Public License for more details.
13 |
14 | // You should have received a copy of the GNU General Public License
15 | // along with this program. If not, see .
16 | // _______________________________________________________________________
17 |
18 |
19 |
20 | // imageHandling.h
21 | // - definitions of structures to hold gray level and rgb images
22 | // - methods to allocate and free memory
23 | // - reading and writing TIFF images
24 |
25 | /*
26 | ideas pursued in this code:
27 | 0. No additional comments, aim is to have the code itself understandable
28 | 1. new_...() only allocates memory, values are not set
29 | 2. new_..() operates only if data containing arrays point to NULL
30 | 3. delete_...() releases memory and sets pointers on data containing fields to NULL
31 | 4. methods do not allocate or release memory (reentrance safe?)
32 | 5. pixel coordinates are ordered as in mathematics: x,y
33 | 6. using a memState_objectXY varibale to keep track of allocation and freeing memory in the main() is advised!
34 | 7. return value 0 <-> OK, other <-> ERROR
35 | 8. methods only report in case of problems, they are quiet in case of success (main() shall decide when to report success)
36 |
37 | The code is based on the one used for the "Monolith 2" project conducted IML, University of Basel. The code here is an extensively reorganized version of that code.
38 | */
39 |
40 | // imageHandling.h
41 | // - declaration of types to hold images
42 | // - ceclaration of methods for handling of such images
43 | // - declaration of methods for reading from and writing to TIFF
44 | #ifndef doLCE_imageHandling_h
45 | #define doLCE_imageHandling_h
46 |
47 |
48 |
49 | // *** imageTypes.h ***
50 | // **************************************
51 |
52 | typedef struct{
53 | int width, height;
54 | int **img;
55 | int memState;
56 | } glImage_t;
57 |
58 | int new_glImage( glImage_t *glImage, int width, int height );
59 |
60 | int delete_glImage( glImage_t *glImage );
61 |
62 | typedef struct{
63 | int width, height;
64 | int ***img;
65 | int memState;
66 | } rgbImage_t;
67 |
68 | int new_rgbImage( rgbImage_t *rgbImage, int width, int height );
69 |
70 | int delete_rgbImage( rgbImage_t *rgbImage );
71 |
72 |
73 | // *** handlingTIFF.h ***
74 | // **********************
75 | int check_TIFF( char *TIFFname, short *spp, short *bps, int *width, int *height );
76 |
77 | int read_TIFF_glImage( char *fromTIFFname, glImage_t *glImage );
78 |
79 | int read_16bitTIFF_glImage( char *fromTIFFname, glImage_t *glImage );
80 |
81 | int read_3x8bitTIFF_rgbImage( char *fromTIFFname, rgbImage_t *rgbImage );
82 |
83 | int read_3x16bitTIFF_rgbImage( char *fromTIFFname, rgbImage_t *rgbImage );
84 |
85 | int write_16bitTIFF_glImage( glImage_t *glImage, char *toTIFFname );
86 |
87 | int write_3x8bitTIFF_rgbImage( rgbImage_t *rgbImage, char *toTIFFname );
88 |
89 | int writeROI_3x8bitTIFF_rgbImage( rgbImage_t *rgbImage, char *toTIFFname, int roiXpos, int roiYpos, int roiWidth, int roiHeight );
90 |
91 | int write_3x16bitTIFF_rgbImage( rgbImage_t *rgbImage, char *toTIFFName ); // currently implementing...
92 |
93 |
94 |
95 | // *** geometryTypes.h ***
96 | // **********************************************
97 | typedef struct {
98 | int x, y;
99 | } point_t;
100 |
101 | // to do: line, rectangle
102 |
103 |
104 | typedef struct {
105 | int length;
106 | int *list; //point_t coo[]; to be changed from int array to point_t array once I know how that works...
107 | int memState;
108 | } positionList_t;
109 |
110 | int new_positionList( positionList_t *positions, int length );
111 |
112 | int delete_positionList( positionList_t *positions );
113 |
114 | /*
115 | int pick_NonzeroPositions_fromProfile( glprofile_t *profile, positionList_t *positions );
116 | */
117 |
118 |
119 | // *** grayLevelAnalysis.h ***
120 | // ****************************************
121 | int minMax_glImage( glImage_t *glImage, int *minGl, int *maxGl ); // should be called get_range_glImage()
122 |
123 | int get_range_rgbImage( rgbImage_t *rgbImage, int minValue[3], int maxValue[3] );
124 |
125 | typedef struct {
126 | int minGl;
127 | int maxGl;
128 | unsigned long *freq;
129 | int memState;
130 | } glHistogram_t;
131 |
132 | int new_glHistogram( glHistogram_t *glHist, int minGl, int maxGl );
133 |
134 | int delete_glHistogram( glHistogram_t *glHist );
135 |
136 | int get_glHistogram( glImage_t *glImage, glHistogram_t *glHist );
137 |
138 | int get_glHistograms_fourShot( glImage_t *glImage, glHistogram_t glHists[4] );
139 |
140 | int write_glHistogram( glHistogram_t *glHist, char *toFileName );
141 |
142 | int write_glHistograms_fourShot( glHistogram_t glHists[4], char *toFileName );
143 |
144 | typedef struct {
145 | int direction; // 0 <-> along x, 1 <-> along y
146 | point_t p;
147 | int length;
148 | int thickness; // number of pixel summed over in perpendicular direction
149 | long *glSum; // need long to avoid overflow!
150 | int memState; // 0 <-> not allocated, -1 <-> unknown (error)
151 | } glProfile_t;
152 |
153 | int new_glProfile( glProfile_t *glProfile, int length );
154 |
155 | int delete_glProfile( glProfile_t *glProfile );
156 |
157 | int get_glProfile( glImage_t *glImage, glProfile_t *glProfile, point_t p, int direction, int thickness );
158 |
159 | int write_glProfile( glProfile_t *glProfile, char *tofileName );
160 |
161 | int copy_glProfile( glProfile_t *glProfileORI, glProfile_t *glProfileCPY );
162 |
163 | int smooth_glProfile( glProfile_t *glProfile );
164 |
165 | //int erode_glProfile( glProfile_t *glProfile );
166 |
167 | int extract_localMinima_glProfile( glProfile_t *profile );
168 |
169 | int extract_wells_glProfile( glProfile_t *profile );
170 |
171 | int get_meanPeakSpacing( glProfile_t *profile, float *peakSpacing );
172 |
173 | int get_peakSpacingHistogram( glProfile_t *profile, int peakSpacingHist[40], int *nPeaks );
174 |
175 | int get_rasterSpacing( int spacingHist[40], int *rasterSpacing );
176 |
177 | int regularize_peakRaster( glProfile_t *glProfile, int rasterSpacing, int *nPeaks ); // rebame Raster to Profile, dito below!!!!!
178 |
179 | int relax_regPeakRaster( glProfile_t *glProfile, glProfile_t *regPeakProfile );
180 |
181 | int count_peaks_glProfile( glProfile_t *profile, int *nPeaks );
182 |
183 | int get_peakPositions( glProfile_t *profile, positionList_t *peakPos );
184 |
185 | int correct_oddPeakPositions( positionList_t *peakPos );
186 |
187 |
188 | // *** reconstructing the colors ***
189 | // *********************************
190 |
191 | int reconstruct_colorFrame( glImage_t *glScan, positionList_t *rasterPos, rgbImage_t *rgbFrame );
192 |
193 | int reconstructInterpolate_colorFrame( glImage_t *glScan, positionList_t *rasterPos, rgbImage_t *rgbFrame );
194 |
195 | int pickColor_interactively( glImage_t *glScan, positionList_t *rasterPos );
196 |
197 | // *** drawingInImages.h ***
198 | // **************************
199 |
200 | int draw_verticalLines_rgbImage( rgbImage_t *rgbImage, positionList_t *positions, int color[3] );
201 |
202 | int draw_raster_rgbImage( rgbImage_t *rgbImage, glProfile_t *profile, positionList_t *positions );
203 |
204 | // to do: lines and rectangles
205 |
206 |
207 | #endif
208 |
209 |
210 | //
211 | /* BEGIN not yet revised code
212 | int write_glImage_TIFF( glImage_t *glImage, char *TIFFname );
213 |
214 | int read_TIFF_rgbImage( char *TIFFname, rgbImage_t *rgbImage );
215 |
216 | int write_rgbImage_TIFF( rgbImage_t *rgbImage, char *TIFFname );
217 | // END not yet revised code
218 | */
219 |
220 | /// WHAT TO DO WITH THAT BELOW?? DON'T YET THROW!
221 |
222 | // all stuff below should better go elsewhere I think (JR Nov 14 2012)
223 | /*
224 | //
225 | // load an 8-bit gl TIFF to a gl image which was allocated with appropriate dimensions
226 | int load_glTIFF_glImage( char *inputTIFFname, bitstore_glImage_t *glImage );
227 | //
228 | // load one channel of an 8-bit rgb TIFF to a gl image which was allocated with appropriate dimensions
229 | int loadChannel_rgbTIFF_glImage( char *inputTIFFname, bitstore_glImage_t *glImage, int channel );
230 | //
231 | int load_rgbTIFF_rgbImage( char *inputTIFFname, bitstore_rgbImage_t *rgbImage );
232 | //
233 |
234 |
235 | // *******************************************
236 | // *** basic handling of gl and rgb images ***
237 | // *******************************************
238 | //
239 | // copy one glImage into another one with same size
240 | int copy_glImage( bitstore_glImage_t *glImg_from, bitstore_glImage_t *glImg_to );
241 | //
242 | // add glImage weighted to channel c E {0,1,2} to an rgb image
243 | int addChannel_rgbImage( bitstore_glImage_t *glImage, bitstore_rgbImage_t *rgbImage, int c, float weight, int yOffset, int xOffset );
244 | //
245 | int set_channel_rgbImage( bitstore_glImage_t *glImage, bitstore_rgbImage_t *rgbImage, int c, float weight );
246 | //
247 | // convert a rgb image to a gray level image.
248 | int convert_rgb2glImage( bitstore_rgbImage_t *rgbImage, bitstore_glImage_t *glImage);
249 | //
250 | // extracts a single channel of a rgb image as gray level image
251 | int extractChannel_rgbImage( bitstore_rgbImage_t *rgbImage, bitstore_glImage_t *glImage, int channel);
252 | //
253 | // copy a subset from a glImage into a smaller one
254 | int copy_glImageROI( bitstore_glImage_t *glImage, bitstore_glImage_t *crpGlImage, int x_offset, int y_offset );
255 | //
256 | // just the maximum of integers
257 | int max( int a, int b );
258 | //
259 | // just the minimum of integers
260 | int min( int a, int b );
261 | //
262 | */
263 |
264 |
--------------------------------------------------------------------------------
/doLCE/imageProcessing.c:
--------------------------------------------------------------------------------
1 | //
2 | // doLCE - do Lenticular film Color rEconstruction -
3 | // Copyright (C) 2012 Joakim Reuteler
4 |
5 | // This program is free software: you can redistribute it and/or modify
6 | // it under the terms of the GNU General Public License version 3 as
7 | // published by the Free Software Foundation.
8 |
9 | // This program is distributed in the hope that it will be useful,
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | // GNU General Public License for more details.
13 |
14 | // You should have received a copy of the GNU General Public License
15 | // along with this program. If not, see .
16 | // _______________________________________________________________________
17 |
18 |
19 |
20 | // imageProcessing.c
21 | // - implementation of simple operations on images
22 |
23 |
24 | #include "imageProcessing.h"
25 |
26 | #include
27 | #include
28 | #include "imageHandling.h"
29 |
30 |
31 |
32 |
33 | // *** unary operations ***
34 | // ************************
35 |
36 | int addGl_glImage( glImage_t *glImage, int gl ) {
37 | int status = 0;
38 |
39 | int i, j;
40 | int minGl, maxGl;
41 |
42 | if ( glImage->img == NULL ) {
43 | status = -1;
44 | printf( "ERROR: addGl_glImage(): Cannot add gray level to empty image.\n" );
45 | }
46 |
47 | if ( status == 0 ) {
48 | for ( j=0; jheight; j++ ) {
49 | for ( i=0; iwidth; i++ ) {
50 | glImage->img[j][i] += gl;
51 | }
52 | }
53 | }
54 |
55 | return status;
56 | }
57 |
58 |
59 | int multiplyGl_glImage( glImage_t *glImage, float factor ) {
60 | int status = 0;
61 |
62 | int width;
63 | int i, j;
64 |
65 | if ( glImage->img==NULL || glImage->memState!=1 ) {
66 | status = -1;
67 | printf ( "ERROR: multiplyGl_glImage(): Invalid argument ''\n" );
68 | }
69 | else if ( factor<0.0 ) {
70 | status = -1;
71 | printf ( "ERROR: multiplyGl_glImage(): Invalid argument ''\n" );
72 | }
73 |
74 | if ( status == 0 ) {
75 | width = glImage->width;
76 | for ( j=0; jheight; j++ ) {
77 | for ( i=0; iimg[j][i] = (int)( factor * glImage->img[j][i] );
79 | }
80 | }
81 | }
82 |
83 | return status;
84 | }
85 |
86 |
87 |
88 |
89 |
90 | int setValue_rgbImage( rgbImage_t *rgbImage, int value ) {
91 | int status = 0;
92 |
93 | int i, j;
94 | int width, height, c;
95 |
96 | if ( rgbImage->img==NULL || rgbImage->memState!=1 ) {
97 | status = -1;
98 | printf ( "ERROR: setZero_rgbImage(): Invalid argument 'rgbImage->img==NULL || rgbImage->memState!=1'\n" );
99 | }
100 |
101 | if ( status == 0 ) {
102 | width = rgbImage->width;
103 | height = rgbImage->height;
104 | for ( c=0; c<3; c++ ) {
105 | for ( j=0; jimg[c][j][i] = value;
108 | }
109 | }
110 | }
111 | }
112 |
113 | return status;
114 | }
115 |
116 |
117 |
118 | int multiplyVal_rgbImage( rgbImage_t *rgbImage, float factors[3] ) {
119 | int status = 0;
120 |
121 | int i, j;
122 | int width, height, c;
123 |
124 | if ( rgbImage->img==NULL || rgbImage->memState!=1 ) {
125 | status = -1;
126 | printf ( "ERROR: multiplyVal_rgbImage(): Invalid argument 'rgbImage->img==NULL || rgbImage->memState!=1'\n" );
127 | }
128 |
129 | if ( status == 0 ) {
130 | width = rgbImage->width;
131 | height = rgbImage->height;
132 | for ( c=0; c<3; c++ ) {
133 | for ( j=0; jimg[c][j][i] = (int)(factors[c]*rgbImage->img[c][j][i]);
136 | }
137 | }
138 | }
139 | }
140 |
141 | return status;
142 | }
143 |
144 |
145 | int subtractVal_rgbImage( rgbImage_t *rgbImage, int values[3] ){
146 | int status = 0;
147 |
148 | int i, j;
149 | int width, height, c;
150 |
151 | if ( rgbImage->img==NULL || rgbImage->memState!=1 ) {
152 | status = -1;
153 | printf ( "ERROR: subtractVal_rgbImage(): Invalid argument 'rgbImage->img==NULL || rgbImage->memState!=1'\n" );
154 | }
155 |
156 | if ( status == 0 ) {
157 | width = rgbImage->width;
158 | height = rgbImage->height;
159 | for ( c=0; c<3; c++ ) {
160 | for ( j=0; jimg[c][j][i] -= values[c];
163 | }
164 | }
165 | }
166 | }
167 |
168 | return status;
169 | }
170 |
171 | // *** binary operations ***
172 | // *************************
173 | int add_glImage_to_rgbImage( glImage_t *glImage, rgbImage_t *rgbImage, int channel ) {
174 | int status = 0;
175 |
176 | int i, j;
177 | int width;
178 |
179 | if ( glImage->img==NULL || glImage->memState!=1 ) {
180 | status = -1;
181 | printf ( "ERROR: add_glImage_to_rgbImage(): Invalid argument 'glImage->img==NULL || glImage->memState!=1'\n" );
182 | }
183 | else if ( rgbImage->img==NULL || rgbImage->memState!=1 ) {
184 | status = -1;
185 | printf ( "ERROR: add_glImage_to_rgbImage(): Invalid argument 'rgbImage->img==NULL || rgbImage->memState!=1'\n" );
186 | }
187 | else if ( channel<0 || channel>2 ) {
188 | status = -1;
189 | printf ( "ERROR: add_glImage_to_rgbImage(): Invalid argument 'channel<0 || channel>2'\n" );
190 | }
191 | else if ( glImage->width!=rgbImage->width || glImage->height!=rgbImage->height ) {
192 | status = -1;
193 | printf ( "ERROR: add_glImage_to_rgbImage(): Unequal image dimensions.\n" );
194 | }
195 |
196 | if ( status == 0 ) {
197 | width = glImage->width;
198 | for ( j=0; jheight; j++ ) {
199 | for ( i=0; iimg[channel][j][i] += glImage->img[j][i];
201 | }
202 | }
203 | }
204 |
205 |
206 | return status;
207 | }
208 |
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
219 |
220 |
221 |
--------------------------------------------------------------------------------
/doLCE/imageProcessing.h:
--------------------------------------------------------------------------------
1 | //
2 | // doLCE - do Lenticular film Color rEconstruction -
3 | // Copyright (C) 2012 Joakim Reuteler
4 |
5 | // This program is free software: you can redistribute it and/or modify
6 | // it under the terms of the GNU General Public Licenseversion 3 as
7 | // published by the Free Software Foundation.
8 |
9 | // This program is distributed in the hope that it will be useful,
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | // GNU General Public License for more details.
13 |
14 | // You should have received a copy of the GNU General Public License
15 | // along with this program. If not, see .
16 | // _______________________________________________________________________
17 |
18 |
19 |
20 | // imageProcessing.h RENAME THIS TO unaryImageoperations.h and also make a binaryImageoperations.h or what ????
21 | // - declarations of simple operations on images
22 | #ifndef doLCE_imageProcessing_h
23 | #define doLCE_imageProcessing_h
24 |
25 | #include "imageHandling.h"
26 |
27 | // *** unary operations ***
28 | // ************************
29 | int addGl_glImage( glImage_t *glImage, int gl );
30 |
31 | int multiplyGl_glImage( glImage_t *glImage, float factor );
32 |
33 | int setValue_rgbImage( rgbImage_t *rgbImage, int value );
34 |
35 | int multiplyVal_rgbImage( rgbImage_t *rgbImage, float factors[3] );
36 |
37 | int subtractVal_rgbImage( rgbImage_t *rgbImage, int values[3] );
38 |
39 | // *** binary operations ***
40 | // *************************
41 | int add_glImage_to_rgbImage( glImage_t *glImage, rgbImage_t *rgbImage, int channel );
42 | /*
43 | int copy_glImage( glImage_t *fromGlImage, glImage_t *toGlImage ); // isn't this imageHandling ???
44 | */
45 | #endif
46 |
--------------------------------------------------------------------------------
/doLCE/interpolationStudy.c:
--------------------------------------------------------------------------------
1 | //
2 | // doLCE - do Lenticular film Color rEconstruction -
3 | // Copyright (C) 2012 Joakim Reuteler
4 |
5 | // This program is free software: you can redistribute it and/or modify
6 | // it under the terms of the GNU General Public License as published by
7 | // the Free Software Foundation, either version 3 of the License.
8 |
9 | // This program is distributed in the hope that it will be useful,
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | // GNU General Public License for more details.
13 |
14 | // You should have received a copy of the GNU General Public License
15 | // along with this program. If not, see .
16 | // _______________________________________________________________________
17 |
18 |
19 |
20 | #include "imageHandling.h"
21 | #include "imageProcessing.h"
22 |
23 | #include
24 | #include
25 | #include
26 |
27 |
28 | int main( int argc, char *argv[] ) {
29 | // processing control
30 | int status = 0;
31 |
32 | // constants
33 | char greetingText[128] = "";
34 | sprintf( greetingText, "*\n**\n*** inStudy - rgb image pixel column interpolation Study ***\n**\n* [%s ~ %s]\n\n", __DATE__, __TIME__);
35 | char copyrightText[200] = "This program is free software under the terms of the GNU General Public License version 3.\nSee .\n\n";
36 | char helpText[] = "inStudy [--help] 'inputFileName'\n";
37 | char inputImageName[128] = "";
38 | char outputImageName[128] = "";
39 |
40 | // variables
41 | int argNo, optNo;
42 | short spp, bps;
43 | int width, height;
44 | int x, y;
45 | int j, i;
46 | int channel;
47 | float a, b;
48 |
49 |
50 | // data
51 | rgbImage_t inImg;
52 | //inImg.img = NULL;
53 | //inImg.memState = 0;
54 | rgbImage_t outImg;
55 | /*printf( "inImg.img = %d, 'inImg.img == NULL' = %d\n", outImg.img, outImg.img == NULL );
56 | printf( "inImg.memState = %d, 'inImg.memState == 0' = %d\n", outImg.memState, outImg.memState == 0 );*/
57 | //outImg.img = NULL;
58 | //outImg.memState = 0;
59 |
60 |
61 | // Plan:
62 | // 1. read an rgb image, copy only one third of the pixel columns (test output)
63 | // 2. reconstruct the missing pixels by interpolation --> output
64 |
65 |
66 | printf( "%s", greetingText );
67 | printf( "%s", copyrightText );
68 |
69 | if ( argc < 2 ) {
70 | status = -1;
71 | printf( "Too few arguments.\n" );
72 | printf( "\n" );
73 | printf( "%s", helpText );
74 | }
75 | else {
76 | optNo = 0;
77 | argNo = 1;
78 | while ( argNo < argc ) {
79 | if ( argv[argNo][0] == '-' ) {
80 | optNo++;
81 | printf( "option '%s' ignored at the moment\n", argv[argNo] );
82 | }
83 | argNo++;
84 | }
85 | //printf( "argc = %d, argNo = %d, optNo = %d\n", argc, argNo, optNo );
86 | if ( optNo+1 != argc-1 ) {
87 | printf( "WARNING: Several input images specified, only first one will be read at the moment.\n" );
88 | }
89 | strcat( inputImageName, argv[optNo+1] );
90 | printf( "image to load : %s\n", inputImageName );
91 | sprintf( outputImageName, "study_%s", inputImageName );
92 | printf( "result will be written to '%s'\n", outputImageName );
93 | }
94 |
95 | if ( status == 0 ) {
96 | printf( "Checking input image...\n" );
97 | status = check_TIFF( inputImageName, &spp, &bps, &width, &height );
98 | if ( status == 0 ) {
99 | printf( "> % 5d samples per pixel \n> % 5d bits per sample\n", spp, bps );
100 | printf( "> % 5d pixels wide\n> % 5d pixels high\n", width, height );
101 | if ( spp != 3 || bps != 16 ) {
102 | status = -1;
103 | printf( "ERROR: Input image must be 16bit rgb!\n" );
104 | }
105 | else {
106 | status = new_rgbImage( &inImg, width, height );
107 | if ( status == 0 ) {
108 | printf( "### allocated memory : 'inImg.memState = %d'\n", inImg.memState );
109 | printf( "Loading image...\n" );
110 | status = read_3x16bitTIFF_rgbImage( inputImageName, &inImg );
111 | if ( status == 0 ) {
112 | printf( "> OK.\n" );
113 | /*
114 | x = y = 0;
115 | while ( x>-1 && y>-1 ) {
116 | printf( "Enter pixel coordinate to get rgb values for inImg! (negative value to quit)\nx = " );
117 | scanf( "%d", &x );
118 | printf( "y = " );
119 | scanf( "%d", &y );
120 | if ( x<0 || x>=inImg.width || y<0 || y>=inImg.height ) {
121 | printf( "values out of range!\n" );
122 | }
123 | else {
124 | printf( "rgb(%d,%d) = %d | %d | %d\n", x, y, inImg.img[0][y][x], inImg.img[1][y][x], inImg.img[2][y][x] );
125 | }
126 | }
127 | */
128 | }
129 | }
130 | }
131 | }
132 | printf( "\n" );
133 | }
134 |
135 | if ( status == 0 ) {
136 | status = new_rgbImage( &outImg, inImg.width, inImg.height );
137 | if ( status == 0 ) {
138 | printf( "### allocated memory : 'outImg.memState = %d'\n", outImg.memState );
139 | printf( "Copying pixels with x mod 2 == 1 to 'outImg'...\n" );
140 | for ( channel=0; channel<3; channel++ ) {
141 | for ( j=0; j OK.\n" );
149 | /*
150 | x = y = 0;
151 | while ( x>-1 && y>-1 ) {
152 | printf( "Enter pixel coordinate to get rgb values for outImg! (negative value to quit)\nx = " );
153 | scanf( "%d", &x );
154 | printf( "y = " );
155 | scanf( "%d", &y );
156 | if ( x<0 || x>=inImg.width || y<0 || y>=inImg.height ) {
157 | printf( "values out of range!\n" );
158 | }
159 | else {
160 | printf( "rgb(%d,%d) = %d | %d | %d\n", x, y, outImg.img[0][y][x], outImg.img[1][y][x], outImg.img[2][y][x] );
161 | }
162 | }
163 | */
164 |
165 | }
166 | }
167 |
168 | if ( status == 0 ) {
169 | printf( "Now interpolating the lost pixel values...\n" );
170 | a = 3.0;
171 | b = 2.0;
172 | for ( channel=0; channel<3; channel++ ) {
173 | for ( j=1; j.
16 | // _______________________________________________________________________
17 | //
18 |
19 |
20 | // lenticularFilmColorRecunstruction.c
21 | // main() providing the command line tool 'doLCE'
22 |
23 |
24 | #include "imageHandling.h"
25 | #include "imageProcessing.h"
26 |
27 | #include
28 | #include
29 | #include
30 |
31 |
32 | int main( int argc, char *argv[] ) {
33 | // processing control
34 | int status = 0;
35 | int troubleshoot = 0;
36 | int relaxRaster = 0;
37 | int lockRasterSpacing = 0;
38 | int highRes = 0;
39 |
40 | // constants
41 | char greetingText[128] = "";
42 | sprintf( greetingText, "*\n**\n*** doLCE - do Lenticular film Color rEconstruction ***\n**\n* [%s ~ %s]\n\n", __DATE__, __TIME__);
43 | char copyrightText[200] = "This program is free software under the terms of the GNU General Public License version 3.\nSee .\n";
44 | char helpText[] = "doLCE [-help] [-highRes] [-profileRelThickness (float)] [-profileRelPosY (float)] [-relaxRaster] [-rasterSpacing (float)] [-troubleshoot] 'inputDir' 'inputBaseName' 'startNo' 'endNo' 'outputDir'\n";
45 |
46 | char inputImageName[128] = "";
47 | char inputDirName[128] = "";
48 | char inputBaseName[128] = "";
49 | char startNoStr[16] = "";
50 | int startNo;
51 | char endNoStr[16] = "";
52 | int endNo;
53 | char outputDirName[128] = "";
54 | char rgbFrameName[128] = "";
55 |
56 | // running variables
57 | int argNo;
58 | int channel;
59 | int i;
60 | int frameNo;
61 | char frameNoFormat[8] = "";
62 | char frameNoStr[16] = "";
63 | int base;
64 |
65 | // data
66 | int width, height;
67 | short spp, bps;
68 | int minGl, maxGl;
69 | glImage_t glScan;
70 | glScan.img = NULL;
71 | glScan.memState = 0;
72 | glHistogram_t glHist;
73 | glHist.freq = NULL;
74 | glHist.memState = 0;
75 | glHistogram_t fourShotGlHists[4];
76 | for ( i=0; i<4; i++ ) {
77 | fourShotGlHists[i].freq = NULL;
78 | fourShotGlHists[i].memState = 0;
79 | }
80 | glProfile_t horProfile;
81 | horProfile.glSum = NULL;
82 | horProfile.memState = 0;
83 | glProfile_t horProfileCpy;
84 | horProfileCpy.glSum = NULL;
85 | horProfileCpy.memState = 0;
86 | rgbImage_t rgbImage;
87 | rgbImage.img = NULL;
88 | rgbImage.memState = 0;
89 | rgbImage_t rgbFrame;
90 | rgbFrame.img = NULL;
91 | rgbFrame.memState = 0;
92 | int rasterSpacing = 0;
93 | int rasterSize;
94 | int nMinima;
95 | int threshold;
96 | int thickness;
97 | positionList_t rasterPos;
98 | rasterPos.list = NULL;
99 | rasterPos.memState = 0;
100 | float meanPeakSpacing;
101 | int nPeaks;
102 | int peakSpacingHist[40];
103 | int rgbMinVal[3], rgbMaxVal[3];
104 | float factors[3];
105 | float buf;
106 | int rgbFrameWidth, rgbFrameHeight;
107 | point_t p;
108 | float profileRelPosY = 0.1;
109 | float profileRelThickness = 0.8;
110 | int relaxDist;
111 | int j;
112 |
113 | int rasterDimX, rasterDimY;
114 | float subPixelPrecisionRasterSpacing = 19.2;
115 |
116 | int perfAreaWidth, perfAreaHeight;
117 | glImage_t perfArea[4];
118 | for ( i=0; i<4; i++ ) {
119 | perfArea[i].img = NULL;
120 | perfArea[i].memState = 0;
121 | }
122 | int perfNoX, perfNoY;
123 | int i_offset, j_offset;
124 | int frameCenterX, frameCenterY;
125 | float perfRelGlThresholds[4] = { 0.95, 0.95, 0.95, 0.95 };
126 |
127 | // troubleshoot stuff
128 | char glHistFileName[128] = ""; //"glHistogram.txt";
129 | char horProfileLocalMinimaName[128] = ""; //horizontalProfile_localMinima.txt";
130 | char horProfileName[128] = ""; //horizontalProfile.txt";
131 | char horProfileSmooName[128] = "";
132 | char horProfileRegRasterName[128] = ""; //horizontalProfile_regularizedRaster.txt";
133 | char outputTIFFname[128] = ""; //output.tif";
134 | char debugTIFFname[128] = ""; //debugImage.tif";
135 | char fourShotGlHistsName[128] = ""; //fourShotHistograms.txt";
136 |
137 | // disclaimer
138 | printf( "\n" );
139 | printf( "%s", greetingText );
140 | printf( "%s", copyrightText );
141 | printf( "\n\n" );
142 |
143 |
144 | // parsing command line input
145 | if ( argc < 6 ) {
146 | status = -1;
147 | printf( "%s", helpText );
148 | printf( "\n" );
149 | }
150 | else {
151 | printf( "\tPARSING input arguments\n" );
152 | for ( argNo=1; argNo1.0 ) {
164 | status = -1;
165 | printf( "ERROR: Invalid value passed by option '-profileRelPosY' : 'profileRelPosY=%f<0.0 || profileRelPosY=%f>1.0'\n", profileRelPosY, profileRelPosY );
166 | }
167 | else {
168 | printf( "y-position of upper left corner of gray level profile relative to image heigth : %f\n", profileRelPosY );
169 | }
170 | }
171 | else if ( strlen(argv[argNo])==20 && strncmp(argv[argNo],"-profileRelThickness",20)==0 ) {
172 | profileRelThickness = atof( argv[++argNo] );
173 | if ( profileRelThickness<0.0 || profileRelThickness>1.0 ) {
174 | status = -1;
175 | printf( "ERROR: Invalid value passed by option '-profileRelThickness' : 'profileRelThickness=%f<0.0 || profileRelThickenss=%f>1.0'\n", profileRelThickness, profileRelThickness );
176 | }
177 | else {
178 | printf( "thickness for gray level profile relative to image height: %f\n", profileRelThickness );
179 | }
180 | }
181 | else if ( strlen(argv[argNo])==13 && strncmp(argv[argNo],"-troubleshoot",13)==0 ) {
182 | troubleshoot = 1;
183 | printf( "troubleshoot mode is ON\n" );
184 | }
185 | else if ( strlen(argv[argNo])==14 && strncmp(argv[argNo],"-rasterSpacing",14)==0 ) {
186 | lockRasterSpacing = 1;
187 | argNo++;
188 | rasterSpacing = atoi( argv[argNo] );
189 | printf( "lockRasterSpacing is ON\n" );
190 | printf( "using rasterSpacing = %d\n", rasterSpacing );
191 | }
192 | else if ( strlen(argv[argNo])==12 && strncmp(argv[argNo],"-relaxRaster",12)==0 ) {
193 | relaxRaster = 1;
194 | printf( "relaxRaster mode is ON\n" );
195 | }
196 | else {
197 | status = -1;
198 | printf( "ERROR: invalid option '%s', try '-help'\n", argv[argNo] );
199 | }
200 | }
201 | if ( status == 0 ) {
202 | if ( argc-argNo < 5 ) {
203 | status = -1;
204 | printf( "ERROR: Not enough arguments, try '-help'\n" );
205 | }
206 | else if (argc-argNo > 5 ) {
207 | status = -1;
208 | printf( "ERROR: Too many arguments, try '-help'\n" ); // actually this cannot really happen since invalid arguments will be detected
209 | }
210 | else {
211 | //printf( "argNo = %d\n", argNo );
212 | strcpy( inputDirName, argv[argNo] );
213 | //printf( "inputDirName = %s\n", inputDirName );
214 | strcpy( inputBaseName, argv[++argNo] );
215 | //printf( "inputBaseName = %s\n", inputBaseName );
216 | strcpy( startNoStr, argv[++argNo] );
217 | //printf( "startNoStr = %s\n", startNoStr );
218 | startNo = atoi( argv[argNo] );
219 | //printf( "startNo = %d\n", startNo );
220 | strcpy( endNoStr, argv[++argNo] );
221 | //printf( "endNoStr = %s\n", endNoStr );
222 | endNo = atoi( argv[argNo] );
223 | //printf( "endNo = %d\n", endNo );
224 | strcpy( outputDirName, argv[++argNo] );
225 | //printf( "outputDirName = %s\n", outputDirName );
226 |
227 | printf( "image sequence to be processed : '%s/%s%s.tif' to '%s/%s%s.tif'\n", inputDirName, inputBaseName, startNoStr, inputDirName, inputBaseName, endNoStr );
228 | printf( "reconstructed rgb frames will be stored as '%s/%s/rgb_%s%s.tif' etc.\n", inputDirName, outputDirName, inputBaseName, startNoStr );
229 | // check if first and last frame exist, check if output directory exists by opening a log file in there, else prompt to get confirmation in order to create that directory !!!!!!
230 | printf( "\nlog of call : '" );
231 | for ( argNo=0; argNo1 && startNoStr[0]==0 ){
248 | status = -1;
249 | printf( "ERROR: Cannot handle this kind of numbering\n" );
250 | printf( "startNoStr[0] == 0\n" );
251 | printf( "startNoStr == %s\n", startNoStr );
252 | }
253 | else {
254 | sprintf( frameNoFormat, "%%d", strlen(startNoStr) );
255 | //printf( "frameNoFormat = %s\n", frameNoFormat );
256 | }
257 | }
258 | }
259 | if ( status == 0 ) {
260 | printf( "\n-------------------loop over frames----------------------\n\n" );
261 | }
262 | for ( frameNo=startNo; frameNo<=endNo && status==0; frameNo++ ) {
263 | sprintf( frameNoStr, frameNoFormat, frameNo );
264 | //printf( "frameNoStr = %s\n", frameNoStr );
265 | sprintf( inputImageName, "%s/%s%s.tif", inputDirName, inputBaseName, frameNoStr );
266 | printf( "***************************************************************************\n" );
267 | printf( "*** processing frame %d/%d ('%s')\n", frameNo-startNo+1, endNo-startNo+1, inputImageName );
268 | sprintf( rgbFrameName, "%s/%s/rgb_%s%s.tif", inputDirName, outputDirName, inputBaseName, frameNoStr );
269 | //printf( "\t giving : %s\n", rgbFrameName );
270 | if ( troubleshoot == 1 ) {
271 | sprintf( glHistFileName, "%s/%s/glHist_%s%s.txt", inputDirName, outputDirName, inputBaseName, frameNoStr );
272 | sprintf( horProfileLocalMinimaName, "%s/%s/horizontalProfile_localMinima_%s%s.txt", inputDirName, outputDirName, inputBaseName, frameNoStr );
273 | sprintf( horProfileName, "%s/%s/horizontalProfile_%s%s.txt", inputDirName, outputDirName, inputBaseName, frameNoStr );
274 | sprintf( horProfileSmooName, "%s/%s/horizontalProfile_smoothed_%s%s.txt", inputDirName, outputDirName, inputBaseName, frameNoStr );
275 | sprintf( horProfileRegRasterName, "%s/%s/horizontalProfile_regularizedRaster_%s%s.txt", inputDirName, outputDirName, inputBaseName, frameNoStr );
276 | sprintf( outputTIFFname, "%s/%s/output_%s%s.tif", inputDirName, outputDirName, inputBaseName, frameNoStr );
277 | sprintf( debugTIFFname, "%s/%s/debugImage_%s%s.tif", inputDirName, outputDirName, inputBaseName, frameNoStr );
278 | sprintf( fourShotGlHistsName, "%s/%s/fourShotHistograms_%s%s.txt", inputDirName, outputDirName, inputBaseName, frameNoStr );
279 | }
280 |
281 | if ( status == 0 ) {
282 | printf( "\tANALYZING frame\n" );
283 | printf( "Checking TIFF...\n" );
284 | status = check_TIFF( inputImageName, &spp, &bps, &width, &height );
285 | if ( status == 0 ) {
286 | printf( "> % 5d samples per pixel \n> % 5d bits per sample\n", spp, bps ); // change into "normal" format: blabla = value ?
287 | printf( "> % 5d pixels wide\n> % 5d pixels high\n", width, height );
288 | if ( glScan.memState == 0 ) {
289 | new_glImage( &glScan, width, height );
290 | printf( "### allocated memory: 'glScan.memState' = %d\n", glScan.memState );
291 | }
292 | if ( glScan.memState == 1 ) {
293 | printf( "Loading TIFF...\n" );
294 | status = read_16bitTIFF_glImage( inputImageName, &glScan );
295 | if ( status == 0 ) {
296 | printf( "> OK.\n" );
297 | }
298 | }
299 | else {
300 | status = -1;
301 | printf( "ERROR: No memory for loading TIFF available.\n" );
302 | }
303 | }
304 | else {
305 | status = 0;
306 | printf( "WARNING: Frame No %d is missing --> KEEPING PREVIOUS FRAME AND WRITING RESULT TO FILE WITH CURRENT FRAME NUMBER! i.e. frame No %d is duplicte of %d\n", frameNo, frameNo, frameNo-1 );
307 | }
308 | }
309 | if ( status==0 ) {
310 | printf( "Checking gray level dynamic...\n" );
311 | status = minMax_glImage( &glScan, &minGl, &maxGl );
312 | if ( status == 0 ) {
313 | printf( "> [% 5d,% 5d] interval of gray levels\n", minGl, maxGl );
314 | if ( glHist.memState == 0 ) {
315 | new_glHistogram( &glHist, minGl, maxGl );
316 | printf( "### allocated memory: 'glHist.memState' = %d\n", glHist.memState );
317 | }
318 | if ( glHist.memState == 1 ) {
319 | printf( "> getting gray level histogram\n" );
320 | status = get_glHistogram( &glScan, &glHist );
321 | if ( status == 0 ) {
322 | printf( "> OK.\n" );
323 | if ( troubleshoot==1 ) {
324 | printf( "> writing gray level histogram to disk\n" );
325 | status = write_glHistogram( &glHist, glHistFileName );
326 | }
327 | }
328 | }
329 | }
330 | }
331 |
332 | if ( status==0 ) {
333 | printf( "Looking for film perforation in corners of gl scan...\n" );
334 | perfAreaWidth = 0.05*glScan.width;
335 | perfAreaHeight = 0.15*glScan.height;
336 | for ( i=0; i<4; i++ ) {
337 | if ( perfArea[i].memState == 0 ) {
338 | status = new_glImage( &perfArea[i], perfAreaWidth, perfAreaHeight );
339 | }
340 | else {
341 | if ( perfArea[i].width!=perfAreaWidth || perfArea[i].height!=perfAreaHeight ) {
342 | delete_glImage( &perfArea[i] );
343 | if ( perfArea[i].memState == 0 ) {
344 | status = new_glImage( &perfArea[i], perfAreaWidth, perfAreaHeight );
345 | }
346 | else {
347 | status = -1;
348 | printf( "ERROR: Failed to resize gl images for inspection of gl scan corner to find perforations.\n" );
349 | }
350 | }
351 | }
352 | if ( perfArea[i].memState != 1 ) {
353 | status = -1;
354 | printf( "ERROR: Cannot serach for perforation : 'perfAreas.memState != 1'\n" );
355 | }
356 | }
357 |
358 | if ( status == 0 ) {
359 | for ( perfNoY=0; perfNoY<2; perfNoY++ ) {
360 | for ( perfNoX=0; perfNoX<2; perfNoX++ ) {
361 | //perfX[perfNoX+2*perfNoY] = perfY[perfNoX+2*perfNoY] = 0;
362 | i_offset = perfNoX*(glScan.width - perfAreaWidth);
363 | j_offset = perfNoY*(glScan.height - perfAreaHeight);
364 | for ( j=0; j= (int)(maxGl*perfRelGlThresholds[perfNoX+2*perfNoY]+0.5) ) {
367 | perfArea[perfNoX+2*perfNoY].img[j][i] = 1;
368 | /*
369 | if ( i > perfX[perfNoX+2*perfNoY] ) {
370 | perfX[perfNoX+2*perfNoY] = i;
371 | }
372 | if ( j > perfY[perfNoX+2*perfNoY] ) {
373 | perfY[perfNoX+2*perfNoY] = j;
374 | }
375 | */
376 | }
377 | else {
378 | perfArea[perfNoX+2*perfNoY].img[j][i] = 0;
379 | }
380 | }
381 | }
382 | // need to process perfArea.img in order to get clean perforation hole geometry, e.g. fit a prescibed shape(how to do this?), or apply morphological closing, extraction of largest connected component, use a regio growth method if possible in conjunction with a rather strict threshold, or crosscorrelation with a hole template once the boundaries of the size of the perforation are extarcted from the gl thresholded set
383 | // then find a point from which frame position correction can be computed
384 | }
385 | }
386 | // average the proposed frame centers and store this for position correction (true center of frame)
387 | }
388 | }
389 |
390 | if ( status == 0 ) {
391 | printf( "\n" );
392 | printf( "\tPROCESSING frame\n" );
393 | printf( "Shifting gray levels...\n" );
394 | status = addGl_glImage( &glScan, -1*minGl );
395 | if ( status == 0 ) {
396 | printf( "> OK, checking new gray level dynamic...\n" );
397 | status = minMax_glImage( &glScan, &minGl, &maxGl );
398 | if ( status == 0 ) {
399 | printf( "> [% 5d,% 5d] interval of gray levels\n", minGl, maxGl );
400 | }
401 | }
402 | if ( status==0 && troubleshoot==1 ) {
403 | for ( i=0; i<4 && status==0; i++ ) {
404 | if ( fourShotGlHists[i].memState == 0 ) {
405 | status = new_glHistogram( &(fourShotGlHists[i]), minGl, maxGl );
406 | }
407 | }
408 | if ( status == 0 ) {
409 | for ( i=0; i<4; i++ ) {
410 | printf( "### allocated memory: fourShotGlHists[%d].memState = %d\n", i, fourShotGlHists[i].memState );
411 | if ( fourShotGlHists[i].memState != 1 ) {
412 | status = -1;
413 | }
414 | }
415 | if ( status == 0 ) {
416 | printf( "Getting four shot histograms...\n" );
417 | status = get_glHistograms_fourShot( &glScan, fourShotGlHists );
418 | }
419 | if ( status == 0 ) {
420 | status = write_glHistograms_fourShot( fourShotGlHists, fourShotGlHistsName );
421 | if ( status == 0 ) {
422 | printf( "> Wrote four shot gl histograms to '%s'\n", fourShotGlHistsName );
423 | }
424 | }
425 | }
426 | }
427 | }
428 |
429 | if ( status == 0 ) {
430 | printf( "\n" );
431 | printf( "\tLOCALIZING RASTER...\n" );
432 | printf( "Preparing for getting gray level profile...\n" );
433 | printf( "Setting absolute values for y-position and thickness of profile...\n" );
434 | p.x = 0;
435 | p.y = (int)( profileRelPosY * (glScan.height) + 0.5 );
436 | thickness = (int)( profileRelThickness * (glScan.height) + 0.5 );
437 | printf( "> upper left corner at (x,y) = (%d,%d)\n", p.x, p.y );
438 | printf( "> thickness = %d\n", thickness );
439 | if ( horProfile.memState == 0 ) {
440 | status = new_glProfile( &horProfile, glScan.width-p.x );
441 | if ( status == 0 ) {
442 | printf( "### allocated memory: horProfile.memState = %d\n", horProfile.memState );
443 | status = new_glProfile( &horProfileCpy, glScan.width-p.x );
444 | if ( status==0 && relaxRaster==1 ) {
445 | printf( "### allocated memory: horProfileCpy.memState = %d\n", horProfileCpy.memState );
446 | }
447 | }
448 | }
449 | else if ( horProfile.memState == 1 ) {
450 | if ( horProfile.length != glScan.width-p.x ) {
451 | delete_glProfile( &horProfile );
452 | delete_glProfile( &horProfileCpy );
453 | if ( horProfile.memState == 0 ) {
454 | status = new_glProfile( &horProfile, glScan.width-p.x );
455 | if ( status==0 && relaxRaster==1 ) {
456 | status = new_glProfile( &horProfileCpy, glScan.width-p.x );
457 | }
458 | }
459 | else {
460 | status = -1;
461 | printf( "ERROR: Cannot resize memory to suitable size for 'horProfile'.\n" );
462 | }
463 | }
464 | }
465 | if ( status==0 && horProfile.memState==1 ) {
466 | printf( "Getting gl profile..." );
467 | status = get_glProfile( &glScan, &horProfile, p, 0, thickness );
468 | if ( status == 0 ) {
469 | printf( "> OK.\n" );
470 | if ( relaxRaster == 1 ) {
471 | status = copy_glProfile( &horProfile, &horProfileCpy ); // maybe better to use the smoothed copy?
472 | if ( status == 0 ) {
473 | printf( "> Copied glProfile for later use.\n" );
474 | }
475 | }
476 | if ( troubleshoot==1 ) {
477 | printf( ">>> storing gl profile to '%s'\n", horProfileName );
478 | status = write_glProfile( &horProfile, horProfileName );
479 | }
480 | }
481 | }
482 | if ( status == 0 ) {
483 | printf( "Analyzing gray level profile...\n" );
484 | printf( "> smoothing the gl profile\n" );
485 | status = smooth_glProfile( &horProfile );
486 | if ( status == 0 ) {
487 | printf( "> OK.\n" );
488 | if ( troubleshoot == 1 ) {
489 | printf( ">>> storing smoothed gl profile to '%s'\n", horProfileSmooName );
490 | write_glProfile( &horProfile, horProfileSmooName );
491 | }
492 | /*
493 | printf( "> computing local minima of the profile\n" );
494 | status = extract_localMinima_glProfile( &horProfile );
495 | */
496 | printf( "> extracting wells...\n" );
497 | status = extract_wells_glProfile( &horProfile );
498 | if ( status == 0 ) {
499 | printf( "> OK.\n" );
500 | if ( troubleshoot == 1 ) {
501 | printf( ">>> storing well gray levels to '%s'\n", horProfileLocalMinimaName );
502 | write_glProfile( &horProfile, horProfileLocalMinimaName );
503 | }
504 | //printf( "-------------- interrupting for devel and debugging ------------------------------------------------------------\n" );
505 | //status = -1;
506 | if ( lockRasterSpacing == 0 ) {
507 | printf( "Determining the raster spacing...\n" );
508 | printf( "> counting number of minima\n" );
509 | status = count_peaks_glProfile( &horProfile, &nMinima );
510 | if ( status == 0 ) {
511 | printf( "> nMinima = %d\n", nMinima );
512 | printf( "> computing histogram of distances between minima\n" );
513 | status = get_peakSpacingHistogram( &horProfile, peakSpacingHist, &nPeaks );
514 | printf( "> dist\tcount\n" );
515 | if ( status == 0 ) {
516 | for ( i=0; i<40; i++ ) {
517 | if ( peakSpacingHist[i] > 0 ) {
518 | printf( "> %d\t%d\n", i, peakSpacingHist[i] );
519 | }
520 | }
521 | status = get_rasterSpacing( peakSpacingHist, &rasterSpacing );
522 | if ( status == 0 ) {
523 | printf( "> rasterSpacing = %d\n", rasterSpacing );
524 | }
525 | }
526 | }
527 | }
528 | if ( status == 0 ) {
529 | printf( "Checking deviation of determined raster spacing to *currently* hard coded sub pixel precision raster spacing\n");
530 | if ( (rasterSpacing-(int)(subPixelPrecisionRasterSpacing+0.5)) > 1 ) {
531 | rasterSpacing = (int)(subPixelPrecisionRasterSpacing+0.5); // skipped retaining of tendency (the '+1')
532 | printf( "> determined raster spacing too large, have set it to %d\n", rasterSpacing );
533 | }
534 | else if ( (rasterSpacing-(int)(subPixelPrecisionRasterSpacing+0.5)) < 1 ) {
535 | rasterSpacing = (int)(subPixelPrecisionRasterSpacing+0.5); // skipped tendency keeping
536 | printf( "> determined raster spacing too small, have set it to %d\n", rasterSpacing );
537 | }
538 | }
539 | if ( status ==0 ) {
540 | printf( "Regularizing peaks...\n" );
541 | // rasterSize = nPeaks;
542 | status = regularize_peakRaster( &horProfile, rasterSpacing, &rasterSize );
543 | // skip and continue with color reconstruction if no peaks were detected using the previous raster point list
544 | if ( status==0 ) {
545 | if ( rasterSize>0 ) {
546 | printf( "> OK.\n" );
547 | if ( troubleshoot == 1 ) {
548 | printf( "> storing profile containing regularized raster to '%s'\n", horProfileRegRasterName );
549 | status = write_glProfile( &horProfile, horProfileRegRasterName );
550 | }
551 | if ( status==0 && relaxRaster==1 ) {
552 | printf( "Relaxing regularized raster positions into local minima...\n" );
553 | status = relax_regPeakRaster( &horProfileCpy, &horProfile );
554 | }
555 | if ( status == 0 ) {
556 | if ( rasterPos.memState == 0 ) {
557 | status = new_positionList( &rasterPos, rasterSize );
558 | if ( status == 0 ) {
559 | printf( "### Allocated memory: 'rasterPos.memState' = %d\n", rasterPos.memState );
560 | }
561 | }
562 | if ( rasterPos.memState == 1 ) {
563 | if ( rasterPos.length != rasterSize ) {
564 | delete_positionList( &rasterPos );
565 | if ( rasterPos.memState == 0 ) {
566 | status = new_positionList( &rasterPos, rasterSize );
567 | if ( status == 0 ) {
568 | printf( "### resized memory: 'rasterPos.memState' = %d\n", rasterPos.memState );
569 | }
570 | }
571 | else {
572 | status = -1;
573 | printf( "ERROR: Cannot resize memory for 'rasterPos' point list.\n" );
574 | }
575 | }
576 | if ( status == 0 ) {
577 | printf( "> transfering raster positions from profile into list\n" );
578 | status = get_peakPositions( &horProfile, &rasterPos );
579 | if ( status == 0 ) {
580 | printf( "> OK.\n" );
581 | printf( "Correcting odd raster positions...\n" );
582 | status = correct_oddPeakPositions( &rasterPos );
583 | if ( status == 0 ) {
584 | printf( "> OK.\n" );
585 | }
586 | }
587 | }
588 | }
589 | }
590 | }
591 | else {
592 | printf( "WARNING: 'rasterSize == %d' --> using raster position list from previous frame!\n", rasterSize );
593 | rasterSize = rasterPos.length;
594 | }
595 | }
596 | }
597 | }
598 | }
599 | }
600 | }
601 | // }
602 |
603 | if ( status == 0 ) {
604 | printf( "\n" );
605 | printf( "\tRECONSTRUCTING COLORS...\n" );
606 | printf( "Computing image dimensions for color reconstructed frame...\n" );
607 | if ( highRes == 1 ) {
608 | rgbFrameWidth = 2*(rasterSize-1)-1;
609 | rgbFrameHeight = ((rgbFrameWidth)*(glScan.height))/glScan.width;
610 | }
611 | else {
612 | rgbFrameWidth = rasterSize-1;
613 | rgbFrameHeight = (rasterSize*glScan.height/glScan.width)+1;
614 | }
615 | printf( "rgbFrame.width = %d, rgbFrame.height = %d\n", rgbFrameWidth, rgbFrameHeight );
616 | if ( rgbFrame.memState == 0 ) {
617 | status = new_rgbImage( &rgbFrame, rgbFrameWidth, rgbFrameHeight );
618 | if ( status == 0 ) {
619 | printf( "### Allocated memory: 'rgbFrame.memState' = %d\n", rgbFrame.memState );
620 | }
621 | }
622 | else if ( rgbFrame.memState == 1 ) {
623 | if ( rgbFrame.width!=rgbFrameWidth || rgbFrame.height!=rgbFrameHeight ) {
624 | printf( "WARNING: The current raster dimension differs from the one detected in the previous frame. This means the reconstructed rgb frames will have inconsistent dimensions.\n" );
625 | delete_rgbImage( &rgbFrame );
626 | if ( rgbFrame.memState == 0 ) {
627 | status = new_rgbImage( &rgbFrame, rgbFrameWidth, rgbFrameHeight );
628 | if ( status == 0 ) {
629 | printf( "### Allocated memory: 'rgbFrame.memState' = %d\n", rgbFrame.memState );
630 | }
631 | }
632 | else {
633 | status = -1;
634 | printf( "ERROR: Cannot free rgbFrame for resizing it.\n" );
635 | }
636 | }
637 | }
638 | else {
639 | status = -1;
640 | printf( "ERROR: Unknown memory state: 'rgbFrame.memState' = %d\n", rgbFrame.memState );
641 | }
642 | if ( status == 0 ) {
643 | printf( "Reconstructing the colors from the gray level scan of the frame and the computed raster for the lenticular lenses...\n" );
644 | if ( highRes == 1 ) {
645 | status = reconstructInterpolate_colorFrame( &glScan, &rasterPos, &rgbFrame );
646 | }
647 | else {
648 | status = reconstruct_colorFrame( &glScan, &rasterPos, &rgbFrame );
649 | }
650 | }
651 | if ( status == 0 ) {
652 | printf( "Compressing color range of reconstructed color frame...\n" );
653 | status = get_range_rgbImage( &rgbFrame, rgbMinVal, rgbMaxVal );
654 | printf( "rgb range after reconstruction:\nchannel\tmin\tmax -> factor\n" );
655 | for( channel=0; channel<3; channel++ ) {
656 | //factors[channel] = 255.0/(rgbMaxVal[channel]);//-rgbMinVal[channel]); // for proper white balance this has to be made in a different manner!!!!
657 | factors[channel] = 255.0/(rgbMaxVal[channel]-rgbMinVal[channel]); // for proper white balance this has to be made in a different manner!!!!
658 | printf( "%d\t%d\t%d -> factor %f\n", channel, rgbMinVal[channel], rgbMaxVal[channel], factors[channel] );
659 | }
660 | status = subtractVal_rgbImage( &rgbFrame, rgbMinVal );
661 | /*buf = factors[0];
662 | if ( buf > factors[1] ) {
663 | buf = factors[1];
664 | }
665 | if ( buf > factors[2] ) {
666 | buf = factors[2];
667 | }
668 | factors[0] = factors[1] = factors[2] = buf;*/
669 | status = multiplyVal_rgbImage( &rgbFrame, factors );
670 | status = get_range_rgbImage( &rgbFrame, rgbMinVal, rgbMaxVal );
671 | printf( "rgb range after compressing to 8bit:\nchannel\tmin\tmax\n" );
672 | for( channel=0; channel<3; channel++ ) {
673 | printf( "%d\t%d\t%d\n", channel, rgbMinVal[channel], rgbMaxVal[channel] );
674 | }
675 | if ( status == 0 ) {
676 | if ( (status = write_3x8bitTIFF_rgbImage( &rgbFrame, rgbFrameName )) == 0 ) {
677 | printf( "> Stored rgb frame to '%s'.\n", rgbFrameName );
678 | }
679 | }
680 | }
681 |
682 | if ( troubleshoot == 1 ) {
683 | printf( "Creating raster localization debug image...\n" ); // conceptionally it is mor clean to do this after the localization procedure happened (as it was done before implementing the processing of a whole frame series)
684 | if ( rgbImage.memState == 0 ) {
685 | status = new_rgbImage( &rgbImage, glScan.width, glScan.height );
686 | if ( status == 0 ) {
687 | printf( "### allocated memory: horProfile.memState = %d\n", horProfile.memState );
688 | }
689 | }
690 | if ( rgbImage.memState == 1 ) {
691 | if ( rgbImage.width!=glScan.width || rgbImage.height!=glScan.height ) {
692 | delete_rgbImage( &rgbImage );
693 | if ( rgbImage.memState == 0 ) {
694 | status = new_rgbImage( &rgbImage, glScan.width, glScan.height );
695 | if ( status == 0 ) {
696 | printf( "### resized memory: rgbImage.memState = %d\n", rgbImage.memState );
697 | }
698 | else {
699 | status = -1;
700 | printf( "ERROR: Could not resize memory for rgbImage.\n" );
701 | }
702 | }
703 | }
704 | if ( status == 0 ) {
705 | printf( "> Compressing gray level dynamic of glScan: [% 5d,% 5d]*%f = [0,255].\n", minGl, maxGl, 255.0/maxGl );
706 | status = multiplyGl_glImage( &glScan, (255.0/maxGl) );
707 | if ( status == 0 ) {
708 | status = minMax_glImage( &glScan, &minGl, &maxGl );
709 | if ( status == 0 ) {
710 | printf( "> gl range now [% 5d,% 5d]\n", minGl, maxGl );
711 | }
712 | }
713 | }
714 | if ( status==0 ) {
715 | status = setValue_rgbImage( &rgbImage, 0 );
716 | if ( status == 0 ) {
717 | for ( channel=0; channel<3 && status==0; channel++ ) {
718 | status = add_glImage_to_rgbImage( &glScan, &rgbImage, channel );
719 | }
720 | }
721 | }
722 | if ( status==0 ) {
723 | status = draw_raster_rgbImage( &rgbImage, &horProfile, &rasterPos );
724 | if ( status == 0 ) {
725 | printf( "Marking Perforation holes...\n" );
726 | for ( perfNoY=0; perfNoY<2; perfNoY++ ) {
727 | for ( perfNoX=0; perfNoX<2; perfNoX++ ) {
728 | i_offset = perfNoX*(glScan.width - perfAreaWidth);
729 | j_offset = perfNoY*(glScan.height - perfAreaHeight);
730 | for ( j=0; j 0 ) {
733 | rgbImage.img[0][j_offset+j][i_offset+i] = 220;
734 | rgbImage.img[1][j_offset+j][i_offset+i] = 220;
735 | rgbImage.img[2][j_offset+j][i_offset+i] = 0;
736 | }
737 | }
738 | }
739 | }
740 | }
741 | if ( (status = write_3x8bitTIFF_rgbImage( &rgbImage, debugTIFFname )) == 0 ) {
742 | printf( "> Stored rgb debug image to '%s'.\n", debugTIFFname );
743 | }
744 | }
745 | }
746 | }
747 | else {
748 | status = -1;
749 | printf( "ERROR: No memory for debug image\n" );
750 | }
751 | }
752 |
753 | }
754 | printf( "*** done processing frame No %d\n", frameNo );
755 | printf( "***************************************************************************\n\n" );
756 | }
757 | if ( status == 0 ) {
758 | printf( "\n---------------------end loop over frames------------------------\n" );
759 | }
760 | }
761 | }
762 |
763 |
764 |
765 | if ( glScan.memState != 0 ) {
766 | printf( "\n\tCLEANING up heap\n" );
767 | delete_glImage( &glScan );
768 | printf( "> freed memory: 'glScan.memState' = %d\n", glScan.memState );
769 | }
770 | if ( rgbFrame.memState != 0 ) {
771 | delete_rgbImage( &rgbFrame );
772 | printf( "> freed memory: 'glScan.memState' = %d\n", rgbFrame.memState );
773 | }
774 | if ( rgbImage.memState != 0 ) {
775 | delete_rgbImage( &rgbImage );
776 | printf( "> freed memory: 'glScan.memState' = %d\n", rgbImage.memState );
777 | }
778 | if ( glHist.memState != 0 ) {
779 | delete_glHistogram( &glHist );
780 | printf( "> freed memory: 'glHist.memState' = %d\n", glHist.memState );
781 | }
782 | for ( i=0; i<4; i++ ) {
783 | if ( fourShotGlHists[i].memState != 0 ) {
784 | delete_glHistogram( &(fourShotGlHists[i]) );
785 | printf( "> freed memory: 'fourShotGlHists[%d].memState' = %d\n", i, fourShotGlHists[i].memState );
786 | }
787 | }
788 | if ( horProfile.memState != 0 ) {
789 | delete_glProfile( &horProfile );
790 | printf( "> freed memory: 'horProfile.memState = %d'\n", horProfile.memState );
791 | }
792 | if ( horProfileCpy.memState != 0 ) {
793 | delete_glProfile( &horProfileCpy );
794 | printf( "> freed memory: 'horProfileCpy.memState = %d'\n", horProfileCpy.memState );
795 | }
796 | if ( rasterPos.memState != 0 ) {
797 | delete_positionList( &rasterPos );
798 | printf( "> freed memory: rasterPos.memState = %d\n", rasterPos.memState );
799 | }
800 | for ( i=0; i<4; i++ ) {
801 | if ( perfArea[i].memState != 0 ) {
802 | delete_glImage( &perfArea[i] );
803 | printf( "> freed memory: 'perfArea[%d].memState' = %d\n", i, perfArea[i].memState );
804 | }
805 | }
806 | printf( "\n" );
807 |
808 |
809 | printf( "Exit: status = %d\n", status );
810 | printf( "\n" );
811 | return status;
812 | }
813 |
814 |
--------------------------------------------------------------------------------
/lenticular/Makefile:
--------------------------------------------------------------------------------
1 | CC = gcc
2 | CFLAGS = -Wall -std=c99
3 |
4 | OBJ = imageHandling.o imageProcessing.o
5 | BIN: lenticular framecropper interpolationstudy
6 |
7 | lenticular: lenticular.o $(OBJ)
8 | $(CC) $(CFLAGS) -ltiff lenticular.o $(OBJ) -o lenticular
9 |
10 | framecropper: frameCropper.o $(OBJ)
11 | $(CC) $(CFLAGS) -ltiff frameCropper.o $(OBJ) -o framecropper
12 |
13 | interpolationstudy: interpolationStudy.o $(OBJ)
14 | $(CC) $(CFLAGS) -ltiff interpolationStudy.o $(OBJ) -o interpolationstudy
15 |
16 | obj: $(OBJ)
17 | $(CC) $(OBJ) -c $(OBJ)
18 |
19 | .PHONY: clean
20 | clean:
21 | rm *.o
22 |
--------------------------------------------------------------------------------
/lenticular/README.md:
--------------------------------------------------------------------------------
1 | # Digital Restoration of Lenticular Colours from Greyscale Digitisations
2 |
3 | ## ☛ **This is a work in progress: not ready for use IRL!** ☚
4 |
5 | ### Contributions are very welcome!
6 |
7 | Please:
8 |
9 | - keep the [issue tracker](http://github.com/amiaopensource/lenticular/issues) limited to bug reports and feature requests;
10 | - use the [pull requests](http://github.com/amiaopensource/lenticular/pulls) to submit patches to both the code and its documentation.
11 |
12 | Thank you!
13 |
14 | ### Short-term goals of the project
15 |
16 | - Any idea for a better name than `lenticular`?
17 | - I was told that a logo would be important.
18 | - Understand and document the parameters.
19 | - Upload test files on GitHub. Who can provide some for public usage?
20 | - Fix error handling. In particular avoid the `Segmentation fault: 11` message, most probably due to wrongly set arrays’ indices.
21 | - Allow full path for both the input and the output folder. In particular, the output folder has not to be nested inside the input folder, but can be chosen freely, e.g. on another hard-disk drive.
22 | - Allow to choose the name of the output files.
23 | - Add flags for mandatory parameters and allow free input order.
24 | - Allow the file extensions `.tiff`, `.TIF` and `.TIFF` as well.
25 | - Allow more TIFF flavours to be processed, _in primis_ `rgb48le`, because currently only `gray16le` is supported in `lenticular`. However, the additional interpolation-study tool does work with `rgb48le`. Therefore this should not be too hard to implement.
26 | - Determine automatically the regex for parsing the greyscale frames of the input folder.
27 | - The number of the first and of the last frame to process is needed only for testing a subset of the frames in the folder. If these parameters are not provided, then parse in ascending order all the files in the folder.
28 | - Change the behaviour of the `-highRes` flag: replace with a resolution parameter and set the default to high resolution.
29 |
30 | ### Mid-term goals
31 |
32 | - Could this be a project for the next AMIA Hackday?
33 | - Verify that TIFF is really the best choice as processing format.
34 | - Process any image format supported by FFmpeg.
35 |
36 | ### Long-term goals
37 |
38 | - **CLI:** A command-line program that can be used by other software as well. That way, for example, FFmpeg (`ffmpeg` and `ffplay`) or `mpv` could be compiled with, or the restoration software `Diamant` could use it as a plug-in. The capability to use a library as a filter on the media player allows to show on-the-fly the lenticular colours while reading a greyscale file. This may be useull for quickly check if a film has been shot with the RGB filter on the lens or not.
39 | - **GUI:** A stand-alone program – directly inspired by [AEO-Light](https://usc-imi.github.io/aeo-light/) – that allows to generate the colours of a digitised lenticular movie films, like _Kodacolor_ and _Agfacolor_. This allows to tune the parameters for a better result.
40 |
41 | ---
42 |
43 | ## An alpha release is available for testing purpose
44 |
45 | The program depends on `libtiff`.
46 |
47 | ### How to compile the source
48 |
49 | 1. download the `lenticular` folder
50 | 1. open the terminal
51 | 1. `cd` into the folder
52 | 1. run `make && make clean`
53 |
54 | ### How to run the main tool
55 |
56 | 1. open the terminal
57 | 1. `cd` into the folder
58 | 1. run `./lenticular`
59 |
60 | ### Homebrew
61 |
62 | Alternatively, you can install the modified `lenticular` tool by using Homebrew. Just run the two commands:
63 |
64 | ```sh
65 | brew tap amiaopensource/amiaos
66 | brew install lenticular
67 | ```
68 |
69 | Once installed, run the main tool by the command:
70 |
71 | ```sh
72 | lenticular
73 | ```
74 |
75 | Brew installation and `lenticular` have been successfully tested on the following operating systems:
76 |
77 | - **Linux:** Ubuntu 16.04.3 LTS and 14.04.5 LTS; Slackware 14.2; Debian 7.11
78 | - **Mac:** macOS 10.13.3 and 10.12.6, OS X 10.11.6 and 10.10.5;
79 | - **Windows** Subsystem for Linux (aka Ubuntu 14.04.4 LTS)
80 |
81 | ### Parameters
82 |
83 | ```sh
84 | lenticular 2018-05-26 alpha
85 |
86 | lenticular [-help] [-highRes] [-profileRelThickness (float)]
87 | [-profileRelPosY (float)] [-relaxRaster]
88 | [-rasterSpacing (float)] [-troubleshoot]
89 | 'inputDir' 'inputBaseName' 'startNo' 'endNo' 'outputDir'
90 | ```
91 |
92 | #### Mandatory parameters
93 |
94 | - **inputDir:** path to the input directory, e.g. `~/TEST/SOURCE_FILES/`
95 | - **inputBaseName:** input base filename without the numbering, e.g. `greyscale_`
96 | - **startNo:** number of the first file, e.g. `0001`
97 | - **endNo:** number of the last file, e.g. `0057`
98 | - **outputDir:** output directory, e.g. `NEW_FILES`
99 |
100 | Please note that, like in the original code, as well as in the current version:
101 |
102 | - the parameters must be passed in this order
103 | - the file extension must be `.tif` and the extension `.tiff` is not allowed
104 | - currently only `gray16le` is supported and not `rgb48le`
105 | - in the example above the first input file is `~/TEST/SOURCE_FILES/greyscale_0001.tif`
106 | - the output folder must be nested inside the input folder
107 | - only the name of the output folder must be entered (with the path from the input folder on, if any, but not the full path)
108 | - in the example above the last output file is `~/TEST/SOURCE_FILES/NEW_FILES/rgb_greyscale_0057.tif`
109 | - inconsistent input may provoke a `Segmentation fault: 11` error
110 |
111 | The full command line for the example above would be:
112 | ```sh
113 | lenticular ~/TEST/SOURCE_FILES/ greyscale_ 0001 0057 NEW_FILES
114 | ```
115 |
116 | #### Optional parameters
117 |
118 | - **-help**
119 | - **-highRes:** set this flag for a high-resolution output
120 | - **-profileRelThickness (float)**
121 | - **-profileRelPosY (float)**
122 | - **-relaxRaster**
123 | - **-rasterSpacing (float)**
124 | - **-troubleshoot**
125 |
126 | #### FFmpeg commands to transform input to gray16le
127 |
128 | As currently `lenticular` does only process `gray16le` content, the FFmpeg commands to transcode in this format are provided.
129 |
130 | ##### Single-image based content
131 |
132 | ```sh
133 | ffmpeg -f image2 -i INPUT_FOLDER/input_file_%08d.ext -pix_fmt gray16le OUTPUT_FOLDER/greyscale_%08d.tif
134 | ```
135 |
136 | The following file formats of good digitisations in a 4K resolution give very nice results:
137 | - TIFF `rgb48le`
138 | - DPX 16-bit, 12-bit or 10-bit
139 | - OpenEXR
140 |
141 | ##### Stream-image based content
142 |
143 | ```sh
144 | ffmpeg -i input_file.ext -pix_fmt gray16le OUTPUT_FOLDER/greyscale_%08d.tif
145 | ```
146 |
147 | We have tested so far the following stream-based file formats in 2K resolution:
148 | - FFV1 `gbrp16le` and `yuv444p`
149 | - uncompressed 10-bit
150 | - ProRes 4444 and ProRes 422 HQ
151 |
152 | ### Additional tools
153 |
154 | The original source code comes with the following two additional tools:
155 |
156 | - `interpolationstudy`: pixel column interpolation study on `rgb48le`
157 | - `framecropper`: crop center part of RGB frames
158 |
159 | Note that we just have started to explore the additional tools.
160 |
161 | We have added to the Homebrew formula options to install one or both of them. And, most importantly, please [report](../CONTRIBUTING.md) any findings.
162 |
163 | #### Interpolation study
164 |
165 | To install the interpolation-study tool via Homebrew, run the two commands:
166 |
167 | ```sh
168 | brew tap amiaopensource/amiaos
169 | brew install lenticular --with-interpolationstudy
170 | ```
171 |
172 | Once installed, run the main tool by the command:
173 |
174 | ```sh
175 | interpolationstudy
176 | ```
177 |
178 | which should give:
179 |
180 | ```sh
181 | interpolationstudy 2018-05-26 alpha
182 | RGB image pixel column interpolation study
183 |
184 | interpolationstudy [--help] 'inputFileName'
185 | ```
186 |
187 | Note that:
188 |
189 | - the «option '--help' [is] ignored at the moment», as is any passed flag
190 | - **inputFileName:** currently the input file must be at the same level than `interpolationstudy`. Hmm…
191 | - when only a flag is passed, a `Segmentation fault: 11` occurs
192 |
193 | #### Frame cropper
194 |
195 | To install the frame-cropper tool via Homebrew, run the two commands:
196 |
197 | ```sh
198 | brew tap amiaopensource
199 | brew install lenticular --with-framecropper
200 | ```
201 |
202 | Once installed, run the main tool by the command:
203 |
204 | ```sh
205 | framecropper
206 | ```
207 |
208 | which should give:
209 |
210 |
211 | ```sh
212 | framecropper 2018-05-26 alpha
213 | crop center part of RGB frames
214 |
215 | framecropper 'width' 'height' 'inputBaseName' 'startNo' 'endNo' 'outputDir'
216 | ```
217 |
218 | ---
219 |
220 | ## Copyright, Licence and Disclaimer
221 |
222 | Copyright (c) 2012 Joakim Reuteler
223 | Copyright (c) 2018 AMIA Open Source
224 |
225 | The program is released under a [GNU GPL v3](https://www.gnu.org/licenses/gpl-3.0.en.html) Licence and the documentation is released under a [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) Licence.
226 |
227 | This work is provided «as is» without warranty or support of any kind.
228 |
--------------------------------------------------------------------------------
/lenticular/frameCropper.c:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | *
3 | * frameCropper.c
4 | * - crop center part of RGB frames
5 | *
6 | * This file is part of 'lenticular'.
7 | *
8 | * Copyright (c) 2012 Joakim Reuteler
9 | * Copyright (c) 2018 AMIA Open Source
10 | *
11 | * This program is free software: you can redistribute it and/or modify it
12 | * under the terms of the GNU General Public License version 3 as published
13 | * by the Free Software Foundation.
14 | *
15 | ******************************************************************************/
16 |
17 |
18 |
19 | #include "imageHandling.h"
20 | #include "imageProcessing.h"
21 |
22 | #include
23 | #include
24 | #include
25 |
26 |
27 |
28 | int main( int argc, char *argv[] ) {
29 | int status = 0;
30 |
31 | // constants
32 | char greetingText[128] = "";
33 | sprintf( greetingText, "\nframecropper 2018-05-26 alpha\n crop center part of RGB frames\n\n" );
34 | char helpText[] = "framecropper 'width' 'height' 'inputBaseName' 'startNo' 'endNo' 'outputDir'\n\n";
35 | char inputImageName[128] = "";
36 | char inputBaseName[128] = "";
37 | char startNoStr[16] = "";
38 | int startNo;
39 | char endNoStr[16] = "";
40 | int endNo;
41 | char outputDirName[128] = "";
42 | char outputImageName[128] = "";
43 | int frameNo;
44 | char frameNoFormat[8] = "";
45 | char frameNoStr[16] = "";
46 |
47 | // variables
48 | int argNo;
49 | short spp, bps;
50 | int width, height;
51 | int crpWidth, crpHeight;
52 | int xOffset, yOffset;
53 |
54 | // data
55 | rgbImage_t inImg;
56 | inImg.img = NULL;
57 | inImg.memState = 0;
58 | rgbImage_t outImg;
59 | outImg.img = NULL;
60 | outImg.memState = 0;
61 |
62 | printf( "%s", greetingText );
63 | if ( argc < 2 ) {
64 | printf( "%s", helpText );
65 | exit(0);
66 | } else if ( argc < 7 ) {
67 | printf( "ERROR: Too few arguments.\n\n%s", helpText );
68 | exit(1);
69 | } else {
70 | argNo = 1;
71 | printf( "argNo = %d\n", argNo );
72 | crpWidth = atoi( argv[argNo] );
73 | crpHeight = atoi( argv[++argNo] );
74 | printf( "crpWidth = %d, crpHeight = %d\n", crpWidth, crpHeight );
75 | strcpy( inputBaseName, argv[++argNo] );
76 | strcpy( startNoStr, argv[++argNo] );
77 | startNo = atoi( argv[argNo] );
78 | strcpy( endNoStr, argv[++argNo] );
79 | endNo = atoi( argv[argNo] );
80 | strcpy( outputDirName, argv[++argNo] );
81 | printf( "image sequence to be processed: '%s%s.tif' to '%s%s.tif'\n", inputBaseName, startNoStr, inputBaseName, endNoStr );
82 | printf( "cropped frames will be stored as '%s/crp_%s%s.tif' etc.\n", outputDirName, inputBaseName, startNoStr );
83 | printf( "\nCOMMAND: " );
84 | for ( argNo = 0 ; argNo < argc; argNo++ )
85 | printf( "%s ", argv[argNo] );
86 | printf( "\n" );
87 | if ( strlen(startNoStr) == strlen(endNoStr) ) {
88 | if ( strlen(startNoStr) == 1 )
89 | sprintf( frameNoFormat, "%%d" );
90 | else
91 | sprintf( frameNoFormat, "%%0%dd", (int)strlen(startNoStr) );
92 | } else {
93 | if ( strlen(startNoStr) > 1 && startNoStr[0] == 0 ) {
94 | printf( "ERROR: Cannot handle this kind of numbering:\n" );
95 | printf( " startNoStr[0] == 0\n" );
96 | printf( " startNoStr == %s\n", startNoStr );
97 | exit(1);
98 | }
99 | }
100 | printf( "\n-------------------loop over frames----------------------\n\n" );
101 | for ( frameNo = startNo; frameNo <= endNo && status == 0; frameNo++ ) {
102 | sprintf( frameNoStr, frameNoFormat, frameNo );
103 | sprintf( inputImageName, "%s%s.tif", inputBaseName, frameNoStr );
104 | sprintf( outputImageName, "%s/crp_%s%s.tif", outputDirName, inputBaseName, frameNoStr );
105 | printf( "***************************************************************************\n" );
106 | printf( "*** processing frame %d/%d ('%s')\n", frameNo-startNo + 1, endNo-startNo + 1, inputImageName );
107 | if ( status == 0 ) {
108 | printf( "Checking TIFF...\n" );
109 | status = check_TIFF( inputImageName, &spp, &bps, &width, &height );
110 | if ( status == 0 ) {
111 | printf( "> % 5d samples per pixel\n> % 5d bits per sample\n", spp, bps );
112 | printf( "> % 5d pixels wide\n> % 5d pixels high\n", width, height );
113 | if ( inImg.memState == 1 && (inImg.width != width || inImg.height != height) ) {
114 | delete_rgbImage( &inImg );
115 | printf( "inImg.memState = %d\n", inImg.memState );
116 | }
117 | if ( inImg.memState == 0 ) {
118 | status = new_rgbImage( &inImg, width, height );
119 | printf( "### allocated memory: 'inImg.memState' = %d\n", inImg.memState );
120 | }
121 | if ( inImg.memState == 1 ) {
122 | printf( "Loading TIFF...\n" );
123 | status = read_3x8bitTIFF_rgbImage( inputImageName, &inImg );
124 | if ( status == 0 )
125 | printf( "> OK\n" );
126 | } else {
127 | status = -1;
128 | printf( "ERROR: No memory for loading TIFF available.\n" );
129 | }
130 | }
131 | }
132 | if ( status == 0 ) {
133 | xOffset = (width - crpWidth) / 2;
134 | yOffset = (height - crpHeight) / 2;
135 | printf( "xOffset = %d, yOffset = %d", xOffset, yOffset );
136 | if ( xOffset >= 0 && yOffset >= 0 ) {
137 | printf( "Writing result to disk...\n" );
138 | status = writeROI_3x8bitTIFF_rgbImage( &inImg, outputImageName, xOffset, yOffset, crpWidth, crpHeight );
139 | if ( status == 0 )
140 | printf( "Stored result to '%s'.\n", outputImageName );
141 | } else {
142 | printf( "Skipping image because it is too small.\n" );
143 | }
144 | }
145 | printf( "*** done processing frame %d\n", frameNo );
146 | printf( "***************************************************************************\n\n" );
147 | }
148 | if ( status == 0 )
149 | printf( "\n---------------------end loop over frames------------------------\n" );
150 | }
151 | if ( inImg.memState != 0 ) {
152 | printf( "Cleaning up heap...\n" );
153 | delete_rgbImage( &inImg );
154 | printf( "### freed memory 'inImg.memState = %d'\n", inImg.memState );
155 | }
156 |
157 | return status;
158 | }
159 |
--------------------------------------------------------------------------------
/lenticular/imageHandling.h:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | *
3 | * imageHandling.h
4 | * - declare structures to hold both grey-level and RGB images
5 | * - read and write TIFF images
6 | * - memory handling
7 | *
8 | * This file is part of 'lenticular'.
9 | *
10 | * Copyright (c) 2012 Joakim Reuteler
11 | * Copyright (c) 2018 AMIA Open Source
12 | *
13 | * This program is free software: you can redistribute it and/or modify it
14 | * under the terms of the GNU General Public License version 3 as published
15 | * by the Free Software Foundation.
16 | *
17 | ******************************************************************************/
18 |
19 | /*
20 | ideas pursued in this code:
21 |
22 | 0. No additional comments, aim is to have the code itself understandable
23 | 1. new_...() only allocates memory, values are not set
24 | 2. new_..() operates only if data containing arrays point to NULL
25 | 3. delete_...() releases memory and sets pointers on data containing fields
26 | to NULL
27 | 4. methods do not allocate or release memory (reentrance safe?)
28 | 5. pixel coordinates are ordered as in mathematics: x,y
29 | 6. using a memState_objectXY varibale to keep track of allocation and
30 | freeing memory in the main() is advised!
31 | 7. return value 0 <-> OK, other <-> ERROR
32 | 8. methods only report in case of problems, they are quiet in case of
33 | success (main() shall decide when to report success)
34 |
35 | The code is based on the one used for the "Monolith 2" project conducted
36 | IML, University of Basel. The code here is an extensively reorganized
37 | version of that code.
38 | */
39 |
40 | #ifndef imageHandling
41 | #define imageHandling
42 |
43 |
44 |
45 | // imageTypes.h
46 |
47 | typedef struct {
48 | int width, height;
49 | int **img;
50 | int memState;
51 | } glImage_t;
52 |
53 | int new_glImage( glImage_t *glImage, int width, int height );
54 | int delete_glImage( glImage_t *glImage );
55 |
56 | typedef struct {
57 | int width, height;
58 | int ***img;
59 | int memState;
60 | } rgbImage_t;
61 |
62 | int new_rgbImage( rgbImage_t *rgbImage, int width, int height );
63 | int delete_rgbImage( rgbImage_t *rgbImage );
64 |
65 |
66 |
67 | // handlingTIFF.h
68 |
69 | int check_TIFF( char *TIFFname, short *spp, short *bps, int *width, int *height );
70 | int read_TIFF_glImage( char *fromTIFFname, glImage_t *glImage );
71 | int read_16bitTIFF_glImage( char *fromTIFFname, glImage_t *glImage );
72 | int read_3x8bitTIFF_rgbImage( char *fromTIFFname, rgbImage_t *rgbImage );
73 | int read_3x16bitTIFF_rgbImage( char *fromTIFFname, rgbImage_t *rgbImage );
74 | int write_16bitTIFF_glImage( glImage_t *glImage, char *toTIFFname );
75 | int write_3x8bitTIFF_rgbImage( rgbImage_t *rgbImage, char *toTIFFname );
76 | int writeROI_3x8bitTIFF_rgbImage( rgbImage_t *rgbImage, char *toTIFFname, int roiXpos, int roiYpos, int roiWidth, int roiHeight );
77 | int write_3x16bitTIFF_rgbImage( rgbImage_t *rgbImage, char *toTIFFName );
78 |
79 |
80 |
81 | // geometryTypes.h
82 |
83 | typedef struct {
84 | int x, y;
85 | } point_t;
86 |
87 |
88 |
89 | // to do: line, rectangle
90 |
91 | typedef struct {
92 | int length;
93 | int *list;
94 | int memState;
95 | } positionList_t;
96 |
97 | int new_positionList( positionList_t *positions, int length );
98 | int delete_positionList( positionList_t *positions );
99 |
100 |
101 |
102 | // grayLevelAnalysis.h
103 |
104 | int get_range_glImage( glImage_t *glImage, int *minGl, int *maxGl );
105 | int get_range_rgbImage( rgbImage_t *rgbImage, int minValue[3], int maxValue[3] );
106 |
107 | typedef struct {
108 | int minGl;
109 | int maxGl;
110 | unsigned long *freq;
111 | int memState;
112 | } glHistogram_t;
113 |
114 | int new_glHistogram( glHistogram_t *glHist, int minGl, int maxGl );
115 | int delete_glHistogram( glHistogram_t *glHist );
116 | int get_glHistogram( glImage_t *glImage, glHistogram_t *glHist );
117 | int get_glHistograms_fourShot( glImage_t *glImage, glHistogram_t glHists[4] );
118 | int write_glHistogram( glHistogram_t *glHist, char *toFileName );
119 | int write_glHistograms_fourShot( glHistogram_t glHists[4], char *toFileName );
120 |
121 | typedef struct {
122 | int direction; // 0 <-> along x, 1 <-> along y
123 | point_t p;
124 | int length;
125 | int thickness; // number of pixel summed over in perpendicular direction
126 | long *glSum; // need long to avoid overflow!
127 | int memState; // 0 <-> not allocated, -1 <-> unknown (error)
128 | } glProfile_t;
129 |
130 | int new_glProfile( glProfile_t *glProfile, int length );
131 | int delete_glProfile( glProfile_t *glProfile );
132 | int get_glProfile( glImage_t *glImage, glProfile_t *glProfile, point_t p, int direction, int thickness );
133 | int write_glProfile( glProfile_t *glProfile, char *tofileName );
134 | int copy_glProfile( glProfile_t *glProfileORI, glProfile_t *glProfileCPY );
135 | int smooth_glProfile( glProfile_t *glProfile );
136 | int extract_localMinima_glProfile( glProfile_t *profile );
137 | int extract_wells_glProfile( glProfile_t *profile );
138 | int get_meanPeakSpacing( glProfile_t *profile, float *peakSpacing );
139 | int get_peakSpacingHistogram( glProfile_t *profile, int peakSpacingHist[40], int *nPeaks );
140 | int get_rasterSpacing( int spacingHist[40], int *rasterSpacing );
141 | int regularize_peakRaster( glProfile_t *glProfile, int rasterSpacing, int *nPeaks );
142 | int relax_regPeakRaster( glProfile_t *glProfile, glProfile_t *regPeakProfile );
143 | int count_peaks_glProfile( glProfile_t *profile, int *nPeaks );
144 | int get_peakPositions( glProfile_t *profile, positionList_t *peakPos );
145 | int correct_oddPeakPositions( positionList_t *peakPos );
146 |
147 |
148 |
149 | // reconstructing the colours
150 |
151 | int reconstruct_colorFrame( glImage_t *glScan, positionList_t *rasterPos, rgbImage_t *rgbFrame );
152 | int reconstructInterpolate_colorFrame( glImage_t *glScan, positionList_t *rasterPos, rgbImage_t *rgbFrame );
153 | int pickColor_interactively( glImage_t *glScan, positionList_t *rasterPos );
154 |
155 |
156 |
157 | // drawingInImages.h
158 |
159 | int draw_verticalLines_rgbImage( rgbImage_t *rgbImage, positionList_t *positions, int color[3] );
160 | int draw_raster_rgbImage( rgbImage_t *rgbImage, glProfile_t *profile, positionList_t *positions );
161 |
162 | #endif
163 |
--------------------------------------------------------------------------------
/lenticular/imageProcessing.c:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | *
3 | * imageProcessing.c
4 | * - simple operations on images
5 | *
6 | * This file is part of 'lenticular'.
7 | *
8 | * Copyright (c) 2012 Joakim Reuteler
9 | * Copyright (c) 2018 AMIA Open Source
10 | *
11 | * This program is free software: you can redistribute it and/or modify it
12 | * under the terms of the GNU General Public License version 3 as published
13 | * by the Free Software Foundation.
14 | *
15 | ******************************************************************************/
16 |
17 |
18 |
19 | #include "imageProcessing.h"
20 |
21 | #include
22 | #include
23 | #include "imageHandling.h"
24 |
25 |
26 |
27 | // unary operations
28 |
29 | int addGl_glImage( glImage_t *glImage, int gl ) {
30 | int status = 0;
31 | int i, j;
32 |
33 | if ( glImage->img == NULL ) {
34 | status = -1;
35 | printf( "ERROR: addGl_glImage(): Cannot add grey-level to empty image.\n" );
36 | } else {
37 | for ( j=0; j < glImage->height; j++ )
38 | for ( i=0; i < glImage->width; i++ )
39 | glImage->img[j][i] += gl;
40 | }
41 |
42 | return status;
43 | }
44 |
45 |
46 |
47 | int multiplyGl_glImage( glImage_t *glImage, float factor ) {
48 | int status = 0;
49 | int i, j;
50 | int width;
51 |
52 | if ( glImage->img == NULL || glImage->memState != 1 ) {
53 | status = -1;
54 | printf ( "ERROR: multiplyGl_glImage(): Invalid argument 'glImage->img == NULL || glImage->memState != 1'.\n" );
55 | } else if ( factor < 0.0 ) {
56 | status = -1;
57 | printf ( "ERROR: multiplyGl_glImage(): Invalid argument 'factor < 0.0'.\n" );
58 | } else {
59 | width = glImage->width;
60 | for ( j=0; j < glImage->height; j++ )
61 | for ( i=0; i < width; i++ )
62 | glImage->img[j][i] = (int)( factor * glImage->img[j][i] );
63 | }
64 |
65 | return status;
66 | }
67 |
68 |
69 |
70 | int setValue_rgbImage( rgbImage_t *rgbImage, int value ) {
71 | int status = 0;
72 | int c, i, j;
73 | int width, height;
74 |
75 | if ( rgbImage->img == NULL || rgbImage->memState != 1 ) {
76 | status = -1;
77 | printf ( "ERROR: setZero_rgbImage(): Invalid argument 'rgbImage->img == NULL || rgbImage->memState != 1'.\n" );
78 | } else {
79 | width = rgbImage->width;
80 | height = rgbImage->height;
81 | for ( c=0; c<3; c++ ) {
82 | for ( j=0; j < height; j++ )
83 | for ( i=0; i < width; i++ )
84 | rgbImage->img[c][j][i] = value;
85 | }
86 | }
87 |
88 | return status;
89 | }
90 |
91 |
92 |
93 | int multiplyVal_rgbImage( rgbImage_t *rgbImage, float factors[3] ) {
94 | int status = 0;
95 | int c, i, j;
96 | int width, height;
97 |
98 | if ( rgbImage->img == NULL || rgbImage->memState != 1 ) {
99 | status = -1;
100 | printf ( "ERROR: multiplyVal_rgbImage(): Invalid argument 'rgbImage->img == NULL || rgbImage->memState != 1'.\n" );
101 | } else {
102 | width = rgbImage->width;
103 | height = rgbImage->height;
104 | for ( c=0; c<3; c++ ) {
105 | for ( j=0; j < height; j++ )
106 | for ( i=0; i < width; i++ )
107 | rgbImage->img[c][j][i] = (int)(factors[c] * rgbImage->img[c][j][i]);
108 | }
109 | }
110 |
111 | return status;
112 | }
113 |
114 |
115 |
116 | int subtractVal_rgbImage( rgbImage_t *rgbImage, int values[3] ) {
117 | int status = 0;
118 | int c, i, j;
119 | int width, height;
120 |
121 | if ( rgbImage->img == NULL || rgbImage->memState != 1 ) {
122 | status = -1;
123 | printf ( "ERROR: subtractVal_rgbImage(): Invalid argument 'rgbImage->img == NULL || rgbImage->memState != 1'.\n" );
124 | } else {
125 | width = rgbImage->width;
126 | height = rgbImage->height;
127 | for ( c=0; c<3; c++ ) {
128 | for ( j=0; j < height; j++ )
129 | for ( i=0; i < width; i++ )
130 | rgbImage->img[c][j][i] -= values[c];
131 | }
132 | }
133 |
134 | return status;
135 | }
136 |
137 |
138 |
139 | // binary operation
140 |
141 | int add_glImage_to_rgbImage( glImage_t *glImage, rgbImage_t *rgbImage, int channel ) {
142 | int status = 0;
143 | int i, j;
144 | int width;
145 |
146 | if ( glImage->img == NULL || glImage->memState != 1 ) {
147 | status = -1;
148 | printf ( "ERROR: add_glImage_to_rgbImage(): Invalid argument 'glImage->img == NULL || glImage->memState != 1'.\n" );
149 | } else if ( rgbImage->img == NULL || rgbImage->memState != 1 ) {
150 | status = -1;
151 | printf ( "ERROR: add_glImage_to_rgbImage(): Invalid argument 'rgbImage->img == NULL || rgbImage->memState != 1'.\n" );
152 | } else if ( channel < 0 || channel > 2 ) {
153 | status = -1;
154 | printf ( "ERROR: add_glImage_to_rgbImage(): Invalid argument 'channel < 0 || channel > 2'.\n" );
155 | } else if ( glImage->width != rgbImage->width || glImage->height != rgbImage->height ) {
156 | status = -1;
157 | printf ( "ERROR: add_glImage_to_rgbImage(): Unequal image dimensions.\n" );
158 | } else {
159 | width = glImage->width;
160 | for ( j=0; j < glImage->height; j++ )
161 | for ( i=0; i < width; i++ )
162 | rgbImage->img[channel][j][i] += glImage->img[j][i];
163 | }
164 |
165 | return status;
166 | }
167 |
--------------------------------------------------------------------------------
/lenticular/imageProcessing.h:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | *
3 | * imageProcessing.h
4 | * - declare simple operations on images
5 | *
6 | * This file is part of 'lenticular'.
7 | *
8 | * Copyright (c) 2012 Joakim Reuteler
9 | * Copyright (c) 2018 AMIA Open Source
10 | *
11 | * This program is free software: you can redistribute it and/or modify it
12 | * under the terms of the GNU General Public License version 3 as published
13 | * by the Free Software Foundation.
14 | *
15 | ******************************************************************************/
16 |
17 |
18 |
19 | #ifndef imageProcessing
20 | #define imageProcessing
21 |
22 | #include "imageHandling.h"
23 |
24 | // unary operations
25 |
26 | int addGl_glImage( glImage_t *glImage, int gl );
27 | int multiplyGl_glImage( glImage_t *glImage, float factor );
28 | int setValue_rgbImage( rgbImage_t *rgbImage, int value );
29 | int multiplyVal_rgbImage( rgbImage_t *rgbImage, float factors[3] );
30 | int subtractVal_rgbImage( rgbImage_t *rgbImage, int values[3] );
31 |
32 | // binary operation
33 |
34 | int add_glImage_to_rgbImage( glImage_t *glImage, rgbImage_t *rgbImage, int channel );
35 |
36 | #endif
37 |
--------------------------------------------------------------------------------
/lenticular/interpolationStudy.c:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | *
3 | * interpolationStudy.c
4 | * - RGB image pixel column interpolation study
5 | *
6 | * This file is part of 'lenticular'.
7 | *
8 | * Copyright (c) 2012 Joakim Reuteler
9 | * Copyright (c) 2018 AMIA Open Source
10 | *
11 | * This program is free software: you can redistribute it and/or modify it
12 | * under the terms of the GNU General Public License version 3 as published
13 | * by the Free Software Foundation.
14 | *
15 | ******************************************************************************/
16 |
17 |
18 |
19 | #include "imageHandling.h"
20 | #include "imageProcessing.h"
21 |
22 | #include
23 | #include
24 | #include
25 |
26 |
27 |
28 | int main( int argc, char *argv[] ) {
29 | int status = 0;
30 |
31 | // constants
32 | char greetingText[128] = "";
33 | sprintf( greetingText, "\ninterpolationstudy 2018-05-26 alpha\n RGB image pixel column interpolation study\n\n" );
34 | char helpText[] = "interpolationstudy [--help] 'inputFileName'\n\n";
35 | char inputImageName[128] = "";
36 | char outputImageName[128] = "";
37 |
38 | // variables
39 | int argNo, optNo;
40 | short spp, bps;
41 | int c, i, j;
42 | int width, height;
43 | float a, b;
44 |
45 | // data
46 | rgbImage_t inImg;
47 | rgbImage_t outImg;
48 |
49 | printf( "%s", greetingText );
50 | if ( argc < 2 ) {
51 | printf( "%s", helpText );
52 | exit(0);
53 | } else {
54 | optNo = 0;
55 | argNo = 1;
56 | while ( argNo < argc ) {
57 | if ( argv[argNo][0] == '-' ) {
58 | optNo++;
59 | printf( "WARNING: Option '%s' ignored at the moment.\n", argv[argNo] );
60 | }
61 | argNo++;
62 | }
63 | if ( optNo + 1 != argc - 1 )
64 | printf( "WARNING: Several input images specified, only first one will be read at the\n moment.\n" );
65 | strcat( inputImageName, argv[optNo + 1] );
66 | printf( "image to load: %s\n", inputImageName );
67 | sprintf( outputImageName, "study_%s", inputImageName );
68 | printf( "result will be written to '%s'\n", outputImageName );
69 | printf( "Checking input image...\n" );
70 | status = check_TIFF( inputImageName, &spp, &bps, &width, &height );
71 | if ( status == 0 ) {
72 | printf( "> % 5d samples per pixel\n> % 5d bits per sample\n", spp, bps );
73 | printf( "> % 5d pixels wide\n> % 5d pixels high\n", width, height );
74 | if ( spp != 3 || bps != 16 ) {
75 | printf( "ERROR: Input image must be 16-bit RGB.\n" );
76 | exit(1);
77 | } else {
78 | status = new_rgbImage( &inImg, width, height );
79 | if ( status == 0 ) {
80 | printf( "### allocated memory: 'inImg.memState = %d'\n", inImg.memState );
81 | printf( "Loading image...\n" );
82 | status = read_3x16bitTIFF_rgbImage( inputImageName, &inImg );
83 | if ( status == 0 )
84 | printf( "> OK\n" );
85 | }
86 | }
87 | }
88 | printf( "\n" );
89 | }
90 | if ( status == 0 ) {
91 | status = new_rgbImage( &outImg, inImg.width, inImg.height );
92 | if ( status == 0 ) {
93 | printf( "### allocated memory: 'outImg.memState = %d'\n", outImg.memState );
94 | printf( "Copying pixels with x mod 2 == 1 to 'outImg'...\n" );
95 | for ( c=0; c<3; c++ )
96 | for ( j=0; j < inImg.height; j++ )
97 | for ( i=0; i < inImg.width; i+=2 ) {
98 | outImg.img[c][j][i] = inImg.img[c][j][i];
99 | outImg.img[c][j][i+1] = 0;
100 | }
101 | printf( "> OK\n" );
102 | }
103 | }
104 | if ( status == 0 ) {
105 | printf( "Now interpolating the lost pixel values...\n" );
106 | a = 3.0;
107 | b = 2.0;
108 | for ( c=0; c<3; c++ )
109 | for ( j=1; j < outImg.height-1; j++ )
110 | for ( i=1; i < outImg.width-1; i+=2 )
111 | outImg.img[c][j][i] = (int)((a*(outImg.img[c][j][i-1]+outImg.img[c][j][i+1]) + b*(outImg.img[c][j-1][i-1]+outImg.img[c][j-1][i+1]+outImg.img[c][j+1][i-1]+outImg.img[c][j+1][i+1]))/(2*a+4*b));
112 | }
113 | if ( status == 0 ) {
114 | printf( "Writing result to disk...\n" );
115 | status = write_3x16bitTIFF_rgbImage( &outImg, outputImageName );
116 | if ( status == 0 )
117 | printf( "Stored result to '%s'.\n", outputImageName );
118 | }
119 | if ( inImg.memState != 0 ) {
120 | printf( "Cleaning up heap...\n" );
121 | delete_rgbImage( &inImg );
122 | printf( "### freed memory: 'inImg.memState = %d'\n", inImg.memState );
123 | }
124 | if ( outImg.memState != 0 ) {
125 | delete_rgbImage( &outImg );
126 | printf( "### freed memory: 'outImg.memState = %d'\n", inImg.memState );
127 | }
128 | return status;
129 | }
130 |
--------------------------------------------------------------------------------
/lenticular/lenticular.1:
--------------------------------------------------------------------------------
1 | .TH "lenticular" "1" "https://github.com/amiaopensource/lenticular" "2019\-01\-27" "AMIA Open Source"
2 | .\" Turn off justification for nroff.
3 | .if n .ad l
4 | .\" Turn off hyphenation.
5 | .nh
6 | .SH NAME
7 | \fBlenticular\fR \- Digital restoration of lenticular colours from greyscale digitisations
8 | .SH SYNOPSIS
9 | .SS
10 | .B lenticular
11 | This is the main program for digital restoration of lenticular colours from greyscale digitisations. Currently only the TIFF \fIgray16le\fR is supported.
12 | .SS
13 | .B interpolationstudy
14 | This is an additional tool. Pixel column interpolation study on \fIrgb48le\fR.
15 | .SS
16 | .B framecropper
17 | This is an additional tool. Crop center part of RGB frames.
18 | .SH COPYRIGHT
19 | Copyright (c) 2012 Joakim Reuteler
20 | .LP
21 | Copyright (c) 2018-2019 AMIA Open Source
22 | .SH LICENSE
23 | The program is released under a GNU General Public License version 3 and the documentation is released under a Creative Commons Attribution 4.0 International License.
24 | .SH DISCLAIMER
25 | The lenticular package is provided "as is" without warranty or support of any kind.
26 |
--------------------------------------------------------------------------------
/lenticular/lenticular.c:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | *
3 | * lenticular.c
4 | * - main() providing the command line tool 'lenticular'
5 | *
6 | * This file is part of 'lenticular'.
7 | *
8 | * Copyright (c) 2012 Joakim Reuteler
9 | * Copyright (c) 2018 AMIA Open Source
10 | *
11 | * This program is free software: you can redistribute it and/or modify it
12 | * under the terms of the GNU General Public License version 3 as published
13 | * by the Free Software Foundation.
14 | *
15 | ******************************************************************************/
16 |
17 |
18 |
19 | #include "imageHandling.h"
20 | #include "imageProcessing.h"
21 |
22 | #include
23 | #include
24 | #include
25 |
26 |
27 |
28 | int main( int argc, char *argv[] ) {
29 | // processing control
30 | int status = 0;
31 | int troubleshoot = 0;
32 | int relaxRaster = 0;
33 | int lockRasterSpacing = 0;
34 | int highRes = 0;
35 |
36 | // constants
37 | char greetingText[128] = "";
38 | sprintf( greetingText, "lenticular 2018-05-26 alpha\n digital restoration of lenticular colours from greyscale digitisations\n" );
39 | char helpText[] = "lenticular [-help] [-highRes] [-profileRelThickness (float)]\n [-profileRelPosY (float)] [-relaxRaster]\n [-rasterSpacing (float)] [-troubleshoot]\n 'inputDir' 'inputBaseName' 'startNo' 'endNo' 'outputDir'\n";
40 | char inputImageName[128] = "";
41 | char inputDirName[128] = "";
42 | char inputBaseName[128] = "";
43 | char startNoStr[16] = "";
44 | int startNo = 0;
45 | char endNoStr[16] = "";
46 | int endNo = 0;
47 | char outputDirName[128] = "";
48 | char rgbFrameName[128] = "";
49 |
50 | // running variables
51 | int argNo;
52 | int c, i;
53 | int frameNo;
54 | char frameNoFormat[8] = "";
55 | char frameNoStr[16] = "";
56 |
57 | // data
58 | int width, height;
59 | short spp, bps;
60 | int minGl, maxGl;
61 | glImage_t glScan;
62 | glScan.img = NULL;
63 | glScan.memState = 0;
64 | glHistogram_t glHist;
65 | glHist.freq = NULL;
66 | glHist.memState = 0;
67 | glHistogram_t fourShotGlHists[4];
68 | for ( i=0; i<4; i++ ) {
69 | fourShotGlHists[i].freq = NULL;
70 | fourShotGlHists[i].memState = 0;
71 | }
72 | glProfile_t horProfile;
73 | horProfile.glSum = NULL;
74 | horProfile.memState = 0;
75 | glProfile_t horProfileCpy;
76 | horProfileCpy.glSum = NULL;
77 | horProfileCpy.memState = 0;
78 | rgbImage_t rgbImage;
79 | rgbImage.img = NULL;
80 | rgbImage.memState = 0;
81 | rgbImage_t rgbFrame;
82 | rgbFrame.img = NULL;
83 | rgbFrame.memState = 0;
84 | int rasterSpacing = 0;
85 | int rasterSize;
86 | int nMinima;
87 | int thickness;
88 | positionList_t rasterPos;
89 | rasterPos.list = NULL;
90 | rasterPos.memState = 0;
91 | int nPeaks;
92 | int peakSpacingHist[40];
93 | int rgbMinVal[3], rgbMaxVal[3];
94 | float factors[3];
95 | int rgbFrameWidth, rgbFrameHeight;
96 | point_t p;
97 | float profileRelPosY = 0.1;
98 | float profileRelThickness = 0.8;
99 | int j;
100 | float subPixelPrecisionRasterSpacing = 19.2;
101 | int perfAreaWidth, perfAreaHeight;
102 | glImage_t perfArea[4];
103 | for ( i=0; i<4; i++ ) {
104 | perfArea[i].img = NULL;
105 | perfArea[i].memState = 0;
106 | }
107 | int perfNoX, perfNoY;
108 | int i_offset, j_offset;
109 | float perfRelGlThresholds[4] = { 0.95, 0.95, 0.95, 0.95 };
110 | char glHistFileName[128] = "";
111 | char horProfileLocalMinimaName[128] = "";
112 | char horProfileName[128] = "";
113 | char horProfileSmooName[128] = "";
114 | char horProfileRegRasterName[128] = "";
115 | char outputTIFFname[128] = "";
116 | char debugTIFFname[128] = "";
117 | char fourShotGlHistsName[128] = "";
118 |
119 | printf( "\n%s\n", greetingText );
120 | if ( argc < 2 ) {
121 | printf( "%s\n", helpText );
122 | exit(0);
123 | } else if ( argc < 6 ) {
124 | printf( "ERROR: Too few arguments.\n\n%s\n", helpText );
125 | exit (1);
126 | } else {
127 | printf( "PARSING INPUT ARGUMENTS\n" );
128 | for ( argNo = 1; argNo < argc - 5 && status == 0; argNo++ ) {
129 | if ( strlen(argv[argNo]) == 5 && strncmp(argv[argNo], "-help", 5) == 0 ) {
130 | printf( "%s", helpText );
131 | } else if ( strlen(argv[argNo]) == 8 && strncmp(argv[argNo], "-highRes", 8) == 0 ) {
132 | highRes = 1;
133 | printf( "highRes mode is ON\n" );
134 | } else if ( strlen(argv[argNo]) == 15 && strncmp(argv[argNo], "-profileRelPosY", 15) == 0 ) {
135 | profileRelPosY = atof( argv[++argNo] );
136 | if ( profileRelPosY < 0.0 || profileRelPosY > 1.0 ) {
137 | printf( "ERROR: Invalid value passed by option '-profileRelPosY': 'profileRelPosY = %f < 0.0 || profileRelPosY = %f > 1.0'.\n", profileRelPosY, profileRelPosY );
138 | exit(1);
139 | } else {
140 | printf( "y-position of upper-left corner of grey-level profile relative to image height: %f\n", profileRelPosY );
141 | }
142 | } else if ( strlen(argv[argNo]) == 20 && strncmp(argv[argNo], "-profileRelThickness", 20) == 0 ) {
143 | profileRelThickness = atof( argv[++argNo] );
144 | if ( profileRelThickness < 0.0 || profileRelThickness > 1.0 ) {
145 | printf( "ERROR: Invalid value passed by option '-profileRelThickness': 'profileRelThickness = %f < 0.0 || profileRelThickenss = %f > 1.0'.\n", profileRelThickness, profileRelThickness );
146 | exit(1);
147 | } else {
148 | printf( "thickness for grey-level profile relative to image height: %f\n", profileRelThickness );
149 | }
150 | } else if ( strlen(argv[argNo]) == 13 && strncmp(argv[argNo] ,"-troubleshoot", 13) == 0 ) {
151 | troubleshoot = 1;
152 | printf( "troubleshoot mode is ON\n" );
153 | } else if ( strlen(argv[argNo]) == 14 && strncmp(argv[argNo], "-rasterSpacing", 14) == 0 ) {
154 | lockRasterSpacing = 1;
155 | argNo++;
156 | rasterSpacing = atoi( argv[argNo] );
157 | printf( "'lockRasterSpacing' is ON\n" );
158 | printf( "using 'rasterSpacing' = %d\n", rasterSpacing );
159 | } else if ( strlen(argv[argNo]) == 12 && strncmp(argv[argNo], "-relaxRaster", 12) == 0 ) {
160 | relaxRaster = 1;
161 | printf( "'relaxRaster' mode is ON\n" );
162 | } else {
163 | printf( "ERROR: invalid option '%s'.\n%s", argv[argNo], helpText );
164 | exit(1);
165 | }
166 | }
167 | if ( argc-argNo < 5 ) {
168 | printf( "ERROR: Not enough arguments.\n%s", helpText );
169 | exit(1);
170 | } else if (argc-argNo > 5 ) {
171 | printf( "ERROR: Too many arguments.\n%s", helpText );
172 | exit(1);
173 | } else {
174 | strcpy( inputDirName, argv[argNo] );
175 | strcpy( inputBaseName, argv[++argNo] );
176 | strcpy( startNoStr, argv[++argNo] );
177 | startNo = atoi( argv[argNo] );
178 | strcpy( endNoStr, argv[++argNo] );
179 | endNo = atoi( argv[argNo] );
180 | strcpy( outputDirName, argv[++argNo] );
181 | printf( "image sequence to be processed: '%s/%s%s.tif' to '%s/%s%s.tif'\n", inputDirName, inputBaseName, startNoStr, inputDirName, inputBaseName, endNoStr );
182 | printf( "reconstructed RGB frames will be stored as '%s/%s/rgb_%s%s.tif' etc.\n", inputDirName, outputDirName, inputBaseName, startNoStr );
183 | printf( "\nCOMMAND: " );
184 | for ( argNo = 0; argNo < argc; argNo++ )
185 | printf( "%s ", argv[argNo] );
186 | printf( "\n" );
187 | if ( strlen(startNoStr) == strlen(endNoStr) ) {
188 | if ( strlen(startNoStr) == 1 )
189 | sprintf( frameNoFormat, "%%d" );
190 | else
191 | sprintf( frameNoFormat, "%%0%dd", (int)strlen(startNoStr) );
192 | } else {
193 | if ( strlen(startNoStr) > 1 && startNoStr[0] == 0 ) {
194 | printf( "ERROR: Cannot handle this kind of numbering:\n" );
195 | printf( " startNoStr[0] == 0\n" );
196 | printf( " startNoStr == %s\n", startNoStr );
197 | exit(1);
198 | }
199 | }
200 | }
201 | printf( "\n-------------------loop over frames----------------------\n\n" );
202 | for ( frameNo = startNo; frameNo <= endNo && status == 0; frameNo++ ) {
203 | sprintf( frameNoStr, frameNoFormat, frameNo );
204 | sprintf( inputImageName, "%s/%s%s.tif", inputDirName, inputBaseName, frameNoStr );
205 | printf( "***************************************************************************\n" );
206 | printf( "*** processing frame %d/%d ('%s')\n", frameNo-startNo+1, endNo-startNo+1, inputImageName );
207 | sprintf( rgbFrameName, "%s/%s/rgb_%s%s.tif", inputDirName, outputDirName, inputBaseName, frameNoStr );
208 | if ( troubleshoot == 1 ) {
209 | sprintf( glHistFileName, "%s/%s/glHist_%s%s.txt", inputDirName, outputDirName, inputBaseName, frameNoStr );
210 | sprintf( horProfileLocalMinimaName, "%s/%s/horizontalProfile_localMinima_%s%s.txt", inputDirName, outputDirName, inputBaseName, frameNoStr );
211 | sprintf( horProfileName, "%s/%s/horizontalProfile_%s%s.txt", inputDirName, outputDirName, inputBaseName, frameNoStr );
212 | sprintf( horProfileSmooName, "%s/%s/horizontalProfile_smoothed_%s%s.txt", inputDirName, outputDirName, inputBaseName, frameNoStr );
213 | sprintf( horProfileRegRasterName, "%s/%s/horizontalProfile_regularizedRaster_%s%s.txt", inputDirName, outputDirName, inputBaseName, frameNoStr );
214 | sprintf( outputTIFFname, "%s/%s/output_%s%s.tif", inputDirName, outputDirName, inputBaseName, frameNoStr );
215 | sprintf( debugTIFFname, "%s/%s/debugImage_%s%s.tif", inputDirName, outputDirName, inputBaseName, frameNoStr );
216 | sprintf( fourShotGlHistsName, "%s/%s/fourShotHistograms_%s%s.txt", inputDirName, outputDirName, inputBaseName, frameNoStr );
217 | }
218 | if ( status == 0 ) {
219 | printf( "ANALYSING FRAME\n" );
220 | printf( "Checking TIFF...\n" );
221 | status = check_TIFF( inputImageName, &spp, &bps, &width, &height );
222 | if ( status == 0 ) {
223 | printf( "> % 5d samples per pixel \n> % 5d bits per sample\n", spp, bps );
224 | printf( "> % 5d pixels wide\n> % 5d pixels high\n", width, height );
225 | if ( glScan.memState == 0 ) {
226 | new_glImage( &glScan, width, height );
227 | printf( "### allocated memory: 'glScan.memState' = %d\n", glScan.memState );
228 | }
229 | if ( glScan.memState == 1 ) {
230 | printf( "Loading TIFF...\n" );
231 | status = read_16bitTIFF_glImage( inputImageName, &glScan );
232 | if ( status == 0 )
233 | printf( "> OK\n" );
234 | } else {
235 | status = -1;
236 | printf( "ERROR: No memory available for loading TIFF.\n" );
237 | }
238 | } else {
239 | status = 0;
240 | printf( "WARNING: Frame %d is missing --> KEEPING PREVIOUS FRAME AND WRITING RESULT TO FILE WITH CURRENT FRAME NUMBER, i.e. frame %d is duplicate of %d.\n", frameNo, frameNo, frameNo - 1 );
241 | }
242 | }
243 | if ( status == 0 ) {
244 | printf( "Checking grey-level dynamic...\n" );
245 | status = get_range_glImage( &glScan, &minGl, &maxGl );
246 | if ( status == 0 ) {
247 | printf( "> [% 5d,% 5d] interval of grey levels\n", minGl, maxGl );
248 | if ( glHist.memState == 0 ) {
249 | new_glHistogram( &glHist, minGl, maxGl );
250 | printf( "### allocated memory: 'glHist.memState' = %d\n", glHist.memState );
251 | }
252 | if ( glHist.memState == 1 ) {
253 | printf( "> getting grey-level histogram\n" );
254 | status = get_glHistogram( &glScan, &glHist );
255 | if ( status == 0 ) {
256 | printf( "> OK\n" );
257 | if ( troubleshoot == 1 ) {
258 | printf( "> writing grey-level histogram to disk\n" );
259 | status = write_glHistogram( &glHist, glHistFileName );
260 | }
261 | }
262 | }
263 | }
264 | }
265 | if ( status == 0 ) {
266 | printf( "Looking for film perforation in corners of grey-level scan...\n" );
267 | perfAreaWidth = 0.05 * glScan.width;
268 | perfAreaHeight = 0.15 * glScan.height;
269 | for ( i=0; i<4; i++ ) {
270 | if ( perfArea[i].memState == 0 )
271 | status = new_glImage( &perfArea[i], perfAreaWidth, perfAreaHeight );
272 | else
273 | if ( perfArea[i].width != perfAreaWidth || perfArea[i].height != perfAreaHeight ) {
274 | delete_glImage( &perfArea[i] );
275 | if ( perfArea[i].memState == 0 ) {
276 | status = new_glImage( &perfArea[i], perfAreaWidth, perfAreaHeight );
277 | } else {
278 | status = -1;
279 | printf( "ERROR: Failed to resize grey-level images for inspection of scan corner to find perforations.\n" );
280 | }
281 | }
282 | if ( perfArea[i].memState != 1 ) {
283 | status = -1;
284 | printf( "ERROR: Cannot serach for perforation: 'perfAreas.memState != 1'.\n" );
285 | }
286 | }
287 | if ( status == 0 ) {
288 | for ( perfNoY = 0; perfNoY < 2; perfNoY++ )
289 | for ( perfNoX = 0; perfNoX < 2; perfNoX++ ) {
290 | i_offset = perfNoX * (glScan.width - perfAreaWidth);
291 | j_offset = perfNoY * (glScan.height - perfAreaHeight);
292 | for ( j=0; j < perfAreaHeight; j++ )
293 | for ( i=0; i < perfAreaWidth; i++ )
294 | if ( glScan.img[j + j_offset][i + i_offset] >= (int)(maxGl * perfRelGlThresholds[perfNoX + 2 * perfNoY] + 0.5) )
295 | perfArea[perfNoX + 2 * perfNoY].img[j][i] = 1;
296 | else
297 | perfArea[perfNoX + 2 * perfNoY].img[j][i] = 0;
298 | }
299 | }
300 | }
301 | if ( status == 0 ) {
302 | printf( "\nPROCESSING frame\n" );
303 | printf( "Shifting grey levels...\n" );
304 | status = addGl_glImage( &glScan, -1*minGl );
305 | if ( status == 0 ) {
306 | printf( "> OK, checking new grey-level dynamic...\n" );
307 | status = get_range_glImage( &glScan, &minGl, &maxGl );
308 | if ( status == 0 )
309 | printf( "> [% 5d,% 5d] grey-level interval\n", minGl, maxGl );
310 | }
311 | if ( status == 0 && troubleshoot == 1 ) {
312 | for ( i=0; i<4 && status == 0; i++ )
313 | if ( fourShotGlHists[i].memState == 0 )
314 | status = new_glHistogram( &(fourShotGlHists[i]), minGl, maxGl );
315 | if ( status == 0 ) {
316 | for ( i=0; i<4; i++ ) {
317 | printf( "### allocated memory: 'fourShotGlHists[%d].memState' = %d\n", i, fourShotGlHists[i].memState );
318 | if ( fourShotGlHists[i].memState != 1 )
319 | status = -1;
320 | }
321 | if ( status == 0 ) {
322 | printf( "Getting four shot histograms...\n" );
323 | status = get_glHistograms_fourShot( &glScan, fourShotGlHists );
324 | }
325 | if ( status == 0 ) {
326 | status = write_glHistograms_fourShot( fourShotGlHists, fourShotGlHistsName );
327 | if ( status == 0 )
328 | printf( "> wrote four shot grey-level histograms to '%s'\n", fourShotGlHistsName );
329 | }
330 | }
331 | }
332 | }
333 | if ( status == 0 ) {
334 | printf( "\nLOCALIZING RASTER...\n" );
335 | printf( "Preparing for getting grey-level profile...\n" );
336 | printf( "Setting absolute values for y-position and thickness of profile...\n" );
337 | p.x = 0;
338 | p.y = (int)( profileRelPosY * (glScan.height) + 0.5 );
339 | thickness = (int)( profileRelThickness * (glScan.height) + 0.5 );
340 | printf( "> upper left corner at (x,y) = (%d,%d)\n", p.x, p.y );
341 | printf( "> thickness = %d\n", thickness );
342 | if ( horProfile.memState == 0 ) {
343 | status = new_glProfile( &horProfile, glScan.width - p.x );
344 | if ( status == 0 ) {
345 | printf( "### allocated memory: horProfile.memState = %d\n", horProfile.memState );
346 | status = new_glProfile( &horProfileCpy, glScan.width-p.x );
347 | if ( status == 0 && relaxRaster == 1 )
348 | printf( "### allocated memory: horProfileCpy.memState = %d\n", horProfileCpy.memState );
349 | }
350 | } else if ( horProfile.memState == 1 ) {
351 | if ( horProfile.length != glScan.width - p.x ) {
352 | delete_glProfile( &horProfile );
353 | delete_glProfile( &horProfileCpy );
354 | if ( horProfile.memState == 0 ) {
355 | status = new_glProfile( &horProfile, glScan.width - p.x );
356 | if ( status == 0 && relaxRaster == 1 )
357 | status = new_glProfile( &horProfileCpy, glScan.width - p.x );
358 | } else {
359 | status = -1;
360 | printf( "ERROR: Cannot resize memory to suitable size for 'horProfile'.\n" );
361 | }
362 | }
363 | }
364 | if ( status == 0 && horProfile.memState == 1 ) {
365 | printf( "Getting grey-level profile..." );
366 | status = get_glProfile( &glScan, &horProfile, p, 0, thickness );
367 | if ( status == 0 ) {
368 | printf( "> OK\n" );
369 | if ( relaxRaster == 1 ) {
370 | status = copy_glProfile( &horProfile, &horProfileCpy );
371 | if ( status == 0 )
372 | printf( "> Copied 'glProfile' for later use.\n" );
373 | }
374 | if ( troubleshoot == 1 ) {
375 | printf( ">>> storing grey-level profile to '%s'\n", horProfileName );
376 | status = write_glProfile( &horProfile, horProfileName );
377 | }
378 | }
379 | }
380 | if ( status == 0 ) {
381 | printf( "Analyzing grey-level profile...\n" );
382 | printf( "> smoothing the grey-level profile\n" );
383 | status = smooth_glProfile( &horProfile );
384 | if ( status == 0 ) {
385 | printf( "> OK\n" );
386 | if ( troubleshoot == 1 ) {
387 | printf( ">>> storing smoothed grey-level profile to '%s'\n", horProfileSmooName );
388 | write_glProfile( &horProfile, horProfileSmooName );
389 | }
390 | printf( "> extracting wells...\n" );
391 | status = extract_wells_glProfile( &horProfile );
392 | if ( status == 0 ) {
393 | printf( "> OK\n" );
394 | if ( troubleshoot == 1 ) {
395 | printf( ">>> storing well grey levels to '%s'\n", horProfileLocalMinimaName );
396 | write_glProfile( &horProfile, horProfileLocalMinimaName );
397 | }
398 | if ( lockRasterSpacing == 0 ) {
399 | printf( "Determining the raster spacing...\n" );
400 | printf( "> counting number of minima\n" );
401 | status = count_peaks_glProfile( &horProfile, &nMinima );
402 | if ( status == 0 ) {
403 | printf( "> nMinima = %d\n", nMinima );
404 | printf( "> computing histogram of distances between minima\n" );
405 | status = get_peakSpacingHistogram( &horProfile, peakSpacingHist, &nPeaks );
406 | printf( "> dist\tcount\n" );
407 | if ( status == 0 ) {
408 | for ( i=0; i<40; i++ )
409 | if ( peakSpacingHist[i] > 0 )
410 | printf( "> %d\t%d\n", i, peakSpacingHist[i] );
411 | status = get_rasterSpacing( peakSpacingHist, &rasterSpacing );
412 | if ( status == 0 )
413 | printf( "> rasterSpacing = %d\n", rasterSpacing );
414 | }
415 | }
416 | }
417 | if ( status == 0 ) {
418 | printf( "Checking deviation of determined raster spacing to *currently* hard coded\nsub-pixel precision raster spacing\n");
419 | if ( (rasterSpacing - (int)(subPixelPrecisionRasterSpacing + 0.5)) > 1 ) {
420 | rasterSpacing = (int)(subPixelPrecisionRasterSpacing+ 0.5);
421 | printf( "> determined raster spacing too large, have set it to %d\n", rasterSpacing );
422 | } else if ( (rasterSpacing-(int)(subPixelPrecisionRasterSpacing + 0.5)) < 1 ) {
423 | rasterSpacing = (int)(subPixelPrecisionRasterSpacing + 0.5);
424 | printf( "> determined raster spacing too small, have set it to %d\n", rasterSpacing );
425 | }
426 | }
427 | if ( status == 0 ) {
428 | printf( "Regularising peaks...\n" );
429 | status = regularize_peakRaster( &horProfile, rasterSpacing, &rasterSize );
430 | if ( status == 0 ) {
431 | if ( rasterSize>0 ) {
432 | printf( "> OK\n" );
433 | if ( troubleshoot == 1 ) {
434 | printf( "> storing profile containing regularised raster to '%s'\n", horProfileRegRasterName );
435 | status = write_glProfile( &horProfile, horProfileRegRasterName );
436 | }
437 | if ( status == 0 && relaxRaster == 1 ) {
438 | printf( "Relaxing regularised raster positions into local minima...\n" );
439 | status = relax_regPeakRaster( &horProfileCpy, &horProfile );
440 | }
441 | if ( status == 0 ) {
442 | if ( rasterPos.memState == 0 ) {
443 | status = new_positionList( &rasterPos, rasterSize );
444 | if ( status == 0 )
445 | printf( "### allocated memory: 'rasterPos.memState' = %d\n", rasterPos.memState );
446 | }
447 | if ( rasterPos.memState == 1 ) {
448 | if ( rasterPos.length != rasterSize ) {
449 | delete_positionList( &rasterPos );
450 | if ( rasterPos.memState == 0 ) {
451 | status = new_positionList( &rasterPos, rasterSize );
452 | if ( status == 0 )
453 | printf( "### resized memory: 'rasterPos.memState' = %d\n", rasterPos.memState );
454 | } else {
455 | status = -1;
456 | printf( "ERROR: Cannot resize memory for 'rasterPos' point list.\n" );
457 | }
458 | }
459 | if ( status == 0 ) {
460 | printf( "> transfering raster positions from profile into list\n" );
461 | status = get_peakPositions( &horProfile, &rasterPos );
462 | if ( status == 0 ) {
463 | printf( "> OK\n" );
464 | printf( "Correcting odd raster positions...\n" );
465 | status = correct_oddPeakPositions( &rasterPos );
466 | if ( status == 0 )
467 | printf( "> OK\n" );
468 | }
469 | }
470 | }
471 | }
472 | } else {
473 | printf( "WARNING: 'rasterSize == %d' --> using raster position list from previous frame.\n", rasterSize );
474 | rasterSize = rasterPos.length;
475 | }
476 | }
477 | }
478 | }
479 | }
480 | }
481 | }
482 | if ( status == 0 ) {
483 | printf( "\nRECONSTRUCTING COLORS...\n" );
484 | printf( "Computing image dimensions for color reconstructed frame...\n" );
485 | if ( highRes == 1 ) {
486 | rgbFrameWidth = 2 * (rasterSize - 1) - 1;
487 | rgbFrameHeight = ((rgbFrameWidth) * (glScan.height)) / glScan.width;
488 | } else {
489 | rgbFrameWidth = rasterSize - 1;
490 | rgbFrameHeight = (rasterSize * glScan.height / glScan.width) + 1;
491 | }
492 | printf( "rgbFrame.width = %d, rgbFrame.height = %d\n", rgbFrameWidth, rgbFrameHeight );
493 | if ( rgbFrame.memState == 0 ) {
494 | status = new_rgbImage( &rgbFrame, rgbFrameWidth, rgbFrameHeight );
495 | if ( status == 0 )
496 | printf( "### allocated memory: 'rgbFrame.memState' = %d\n", rgbFrame.memState );
497 | } else if ( rgbFrame.memState == 1 ) {
498 | if ( rgbFrame.width!=rgbFrameWidth || rgbFrame.height!=rgbFrameHeight ) {
499 | printf( "WARNING: The current raster dimension differs from the one detected in the previous frame. This means the reconstructed RGB frames will have inconsistent dimensions.\n" );
500 | delete_rgbImage( &rgbFrame );
501 | if ( rgbFrame.memState == 0 ) {
502 | status = new_rgbImage( &rgbFrame, rgbFrameWidth, rgbFrameHeight );
503 | if ( status == 0 )
504 | printf( "### allocated memory: 'rgbFrame.memState' = %d\n", rgbFrame.memState );
505 | } else {
506 | status = -1;
507 | printf( "ERROR: Cannot free 'rgbFrame' for resizing it.\n" );
508 | }
509 | }
510 | } else {
511 | status = -1;
512 | printf( "ERROR: Unknown memory state: 'rgbFrame.memState' = %d\n", rgbFrame.memState );
513 | }
514 | if ( status == 0 ) {
515 | printf( "Reconstructing the colors from the grey-level scan of the frame and the computed raster for the lenticular lenses...\n" );
516 | if ( highRes == 1 )
517 | status = reconstructInterpolate_colorFrame( &glScan, &rasterPos, &rgbFrame );
518 | else
519 | status = reconstruct_colorFrame( &glScan, &rasterPos, &rgbFrame );
520 | }
521 | if ( status == 0 ) {
522 | printf( "Compressing color range of reconstructed color frame...\n" );
523 | status = get_range_rgbImage( &rgbFrame, rgbMinVal, rgbMaxVal );
524 | printf( "RGB range after reconstruction:\nchannel\tmin\tmax -> factor\n" );
525 | for ( c=0; c<3; c++ ) {
526 | factors[c] = 255.0 / (rgbMaxVal[c] - rgbMinVal[c]);
527 | printf( "%d\t%d\t%d -> factor %f\n", c, rgbMinVal[c], rgbMaxVal[c], factors[c] );
528 | }
529 | status = subtractVal_rgbImage( &rgbFrame, rgbMinVal );
530 | status = multiplyVal_rgbImage( &rgbFrame, factors );
531 | status = get_range_rgbImage( &rgbFrame, rgbMinVal, rgbMaxVal );
532 | printf( "RGB range after compressing to 8 bit:\nc\tmin\tmax\n" );
533 | for ( c=0; c<3; c++ )
534 | printf( "%d\t%d\t%d\n", c, rgbMinVal[c], rgbMaxVal[c] );
535 | if ( status == 0 ) {
536 | if ( (status = write_3x8bitTIFF_rgbImage( &rgbFrame, rgbFrameName )) == 0 )
537 | printf( "> Stored RGB frame to '%s'.\n", rgbFrameName );
538 | }
539 | }
540 | if ( troubleshoot == 1 ) {
541 | printf( "Creating raster localization debug image...\n" );
542 | if ( rgbImage.memState == 0 ) {
543 | status = new_rgbImage( &rgbImage, glScan.width, glScan.height );
544 | if ( status == 0 )
545 | printf( "### allocated memory: horProfile.memState = %d\n", horProfile.memState );
546 | }
547 | if ( rgbImage.memState == 1 ) {
548 | if ( rgbImage.width != glScan.width || rgbImage.height != glScan.height ) {
549 | delete_rgbImage( &rgbImage );
550 | if ( rgbImage.memState == 0 ) {
551 | status = new_rgbImage( &rgbImage, glScan.width, glScan.height );
552 | if ( status == 0 ) {
553 | printf( "### resized memory: 'rgbImage.memState' = %d\n", rgbImage.memState );
554 | } else {
555 | status = -1;
556 | printf( "ERROR: Could not resize memory for 'rgbImage'.\n" );
557 | }
558 | }
559 | }
560 | if ( status == 0 ) {
561 | printf( "> Compressing grey-level dynamic of 'glScan': [% 5d,% 5d]*%f = [0,255].\n", minGl, maxGl, 255.0/maxGl );
562 | status = multiplyGl_glImage( &glScan, (255.0/maxGl) );
563 | if ( status == 0 ) {
564 | status = get_range_glImage( &glScan, &minGl, &maxGl );
565 | if ( status == 0 )
566 | printf( "> grey-level range is now [% 5d,% 5d]\n", minGl, maxGl );
567 | }
568 | }
569 | if ( status == 0 ) {
570 | status = setValue_rgbImage( &rgbImage, 0 );
571 | if ( status == 0 )
572 | for ( c = 0; c < 3 && status == 0; c++ )
573 | status = add_glImage_to_rgbImage( &glScan, &rgbImage, c );
574 | }
575 | if ( status == 0 ) {
576 | status = draw_raster_rgbImage( &rgbImage, &horProfile, &rasterPos );
577 | if ( status == 0 ) {
578 | printf( "Marking perforation holes...\n" );
579 | for ( perfNoY = 0; perfNoY < 2; perfNoY++ ) {
580 | for ( perfNoX = 0; perfNoX < 2; perfNoX++ ) {
581 | i_offset = perfNoX*(glScan.width - perfAreaWidth);
582 | j_offset = perfNoY*(glScan.height - perfAreaHeight);
583 | for ( j=0; j < perfAreaHeight; j++ )
584 | for ( i=0; i < perfAreaWidth; i++ )
585 | if ( perfArea[perfNoX+2*perfNoY].img[j][i] > 0 ) {
586 | rgbImage.img[0][j_offset+j][i_offset+i] = 220;
587 | rgbImage.img[1][j_offset+j][i_offset+i] = 220;
588 | rgbImage.img[2][j_offset+j][i_offset+i] = 0;
589 | }
590 | }
591 | }
592 | if ( (status = write_3x8bitTIFF_rgbImage( &rgbImage, debugTIFFname )) == 0 )
593 | printf( "> Stored RGB debug image to '%s'.\n", debugTIFFname );
594 | }
595 | }
596 | } else {
597 | status = -1;
598 | printf( "ERROR: No memory for debug image.\n" );
599 | }
600 | }
601 | }
602 | printf( "*** done processing frame number %d\n", frameNo );
603 | printf( "***************************************************************************\n\n" );
604 | }
605 | if ( status == 0 )
606 | printf( "\n---------------------end loop over frames------------------------\n" );
607 | }
608 |
609 | if ( glScan.memState != 0 ) {
610 | printf( "\nCLEANING up heap\n" );
611 | delete_glImage( &glScan );
612 | printf( "> freed memory: 'glScan.memState' = %d\n", glScan.memState );
613 | }
614 | if ( rgbFrame.memState != 0 ) {
615 | delete_rgbImage( &rgbFrame );
616 | printf( "> freed memory: 'glScan.memState' = %d\n", rgbFrame.memState );
617 | }
618 | if ( rgbImage.memState != 0 ) {
619 | delete_rgbImage( &rgbImage );
620 | printf( "> freed memory: 'glScan.memState' = %d\n", rgbImage.memState );
621 | }
622 | if ( glHist.memState != 0 ) {
623 | delete_glHistogram( &glHist );
624 | printf( "> freed memory: 'glHist.memState' = %d\n", glHist.memState );
625 | }
626 | for ( i=0; i<4; i++ ) {
627 | if ( fourShotGlHists[i].memState != 0 ) {
628 | delete_glHistogram( &(fourShotGlHists[i]) );
629 | printf( "> freed memory: 'fourShotGlHists[%d].memState' = %d\n", i, fourShotGlHists[i].memState );
630 | }
631 | }
632 | if ( horProfile.memState != 0 ) {
633 | delete_glProfile( &horProfile );
634 | printf( "> freed memory: 'horProfile.memState = %d'\n", horProfile.memState );
635 | }
636 | if ( horProfileCpy.memState != 0 ) {
637 | delete_glProfile( &horProfileCpy );
638 | printf( "> freed memory: 'horProfileCpy.memState = %d'\n", horProfileCpy.memState );
639 | }
640 | if ( rasterPos.memState != 0 ) {
641 | delete_positionList( &rasterPos );
642 | printf( "> freed memory: 'rasterPos.memState = %d'\n", rasterPos.memState );
643 | }
644 | for ( i=0; i<4; i++ ) {
645 | if ( perfArea[i].memState != 0 ) {
646 | delete_glImage( &perfArea[i] );
647 | printf( "> freed memory: 'perfArea[%d].memState' = %d\n", i, perfArea[i].memState );
648 | }
649 | }
650 |
651 | return status;
652 | }
653 |
--------------------------------------------------------------------------------