Compare commits
5
Commits
daf226a80f
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9ff56ce7ef | ||
|
|
5a9cbfc943 | ||
|
|
ef648cc676 | ||
|
|
1c48a53c19 | ||
|
|
ff9dec0eff |
+1
-1
@@ -158,4 +158,4 @@ uv/
|
|||||||
.git/worktrees/
|
.git/worktrees/
|
||||||
|
|
||||||
# ICRA specific
|
# ICRA specific
|
||||||
images/
|
analyses/
|
||||||
|
|||||||
@@ -0,0 +1,676 @@
|
|||||||
|
GNU GENERAL PUBLIC LICENSE
|
||||||
|
Version 3, 29 June 2007
|
||||||
|
|
||||||
|
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||||
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
|
Preamble
|
||||||
|
|
||||||
|
The GNU General Public License is a free, copyleft license for
|
||||||
|
software and other kinds of works.
|
||||||
|
|
||||||
|
The licenses for most software and other practical works are designed
|
||||||
|
to take away your freedom to share and change the works. By contrast,
|
||||||
|
the GNU General Public License is intended to guarantee your freedom to
|
||||||
|
share and change all versions of a program--to make sure it remains free
|
||||||
|
software for all its users. We, the Free Software Foundation, use the
|
||||||
|
GNU General Public License for most of our software; it applies also to
|
||||||
|
any other work released this way by its authors. You can apply it to
|
||||||
|
your programs, too.
|
||||||
|
|
||||||
|
When we speak of free software, we are referring to freedom, not
|
||||||
|
price. Our General Public Licenses are designed to make sure that you
|
||||||
|
have the freedom to distribute copies of free software (and charge for
|
||||||
|
them if you wish), that you can receive source code or can get it if you
|
||||||
|
want it, that you can change the software or use pieces of it in new
|
||||||
|
free programs, and that you know you can do these things.
|
||||||
|
|
||||||
|
To protect your rights, we need to prevent others from denying you
|
||||||
|
these rights or asking you to surrender the rights. Therefore, you have
|
||||||
|
certain responsibilities if you distribute copies of the software, or if
|
||||||
|
you modify it: responsibilities to respect the freedom of others.
|
||||||
|
|
||||||
|
For example, if you distribute copies of such a program, whether
|
||||||
|
gratis or for a fee, you must pass on to the recipients the same
|
||||||
|
freedoms that you received. You must make sure that they, too, receive
|
||||||
|
or can get the source code. And you must show them these terms so they
|
||||||
|
know their rights.
|
||||||
|
|
||||||
|
Developers that use the GNU GPL protect your rights with two steps:
|
||||||
|
(1) assert copyright on the software, and (2) offer you this License
|
||||||
|
giving you legal permission to copy, distribute and/or modify it.
|
||||||
|
|
||||||
|
For the developers' and authors' protection, the GPL clearly explains
|
||||||
|
that there is no warranty for this free software. For both users' and
|
||||||
|
authors' sake, the GPL requires that modified versions be marked as
|
||||||
|
changed, so that their problems will not be attributed erroneously to
|
||||||
|
authors of previous versions.
|
||||||
|
|
||||||
|
Some devices are designed to deny users access to install or run
|
||||||
|
modified versions of the software inside them, although the manufacturer
|
||||||
|
can do so. This is fundamentally incompatible with the aim of
|
||||||
|
protecting users' freedom to change the software. The systematic
|
||||||
|
pattern of such abuse occurs in the area of products for individuals to
|
||||||
|
use, which is precisely where it is most unacceptable. Therefore, we
|
||||||
|
have designed this version of the GPL to prohibit the practice for those
|
||||||
|
products. If such problems arise substantially in other domains, we
|
||||||
|
stand ready to extend this provision to those domains in future versions
|
||||||
|
of the GPL, as needed to protect the freedom of users.
|
||||||
|
|
||||||
|
Finally, every program is threatened constantly by software patents.
|
||||||
|
States should not allow patents to restrict development and use of
|
||||||
|
software on general-purpose computers, but in those that do, we wish to
|
||||||
|
avoid the special danger that patents applied to a free program could
|
||||||
|
make it effectively proprietary. To prevent this, the GPL assures that
|
||||||
|
patents cannot be used to render the program non-free.
|
||||||
|
|
||||||
|
The precise terms and conditions for copying, distribution and
|
||||||
|
modification follow.
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
0. Definitions.
|
||||||
|
|
||||||
|
"This License" refers to version 3 of the GNU General Public License.
|
||||||
|
|
||||||
|
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||||
|
works, such as semiconductor masks.
|
||||||
|
|
||||||
|
"The Program" refers to any copyrightable work licensed under this
|
||||||
|
License. Each licensee is addressed as "you". "Licensees" and
|
||||||
|
"recipients" may be individuals or organizations.
|
||||||
|
|
||||||
|
To "modify" a work means to copy from or adapt all or part of the work
|
||||||
|
in a fashion requiring copyright permission, other than the making of an
|
||||||
|
exact copy. The resulting work is called a "modified version" of the
|
||||||
|
earlier work or a work "based on" the earlier work.
|
||||||
|
|
||||||
|
A "covered work" means either the unmodified Program or a work based
|
||||||
|
on the Program.
|
||||||
|
|
||||||
|
To "propagate" a work means to do anything with it that, without
|
||||||
|
permission, would make you directly or secondarily liable for
|
||||||
|
infringement under applicable copyright law, except executing it on a
|
||||||
|
computer or modifying a private copy. Propagation includes copying,
|
||||||
|
distribution (with or without modification), making available to the
|
||||||
|
public, and in some countries other activities as well.
|
||||||
|
|
||||||
|
To "convey" a work means any kind of propagation that enables other
|
||||||
|
parties to make or receive copies. Mere interaction with a user through
|
||||||
|
a computer network, with no transfer of a copy, is not conveying.
|
||||||
|
|
||||||
|
An interactive user interface displays "Appropriate Legal Notices"
|
||||||
|
to the extent that it includes a convenient and prominently visible
|
||||||
|
feature that (1) displays an appropriate copyright notice, and (2)
|
||||||
|
tells the user that there is no warranty for the work (except to the
|
||||||
|
extent that warranties are provided), that licensees may convey the
|
||||||
|
work under this License, and how to view a copy of this License. If
|
||||||
|
the interface presents a list of user commands or options, such as a
|
||||||
|
menu, a prominent item in the list meets this criterion.
|
||||||
|
|
||||||
|
1. Source Code.
|
||||||
|
|
||||||
|
The "source code" for a work means the preferred form of the work
|
||||||
|
for making modifications to it. "Object code" means any non-source
|
||||||
|
form of a work.
|
||||||
|
|
||||||
|
A "Standard Interface" means an interface that either is an official
|
||||||
|
standard defined by a recognized standards body, or, in the case of
|
||||||
|
interfaces specified for a particular programming language, one that
|
||||||
|
is widely used among developers working in that language.
|
||||||
|
|
||||||
|
The "System Libraries" of an executable work include anything, other
|
||||||
|
than the work as a whole, that (a) is included in the normal form of
|
||||||
|
packaging a Component, but which is not part of that Component, and
|
||||||
|
(b) serves only to enable use of the work with that Component, or to
|
||||||
|
implement a Standard Interface for which an implementation is
|
||||||
|
available to the public in source code form. A "Component" in this
|
||||||
|
context means a major essential component (kernel, window system, and
|
||||||
|
so on) of the specific operating system (if any) on which the
|
||||||
|
executable work runs, or a compiler used to produce the work, or an
|
||||||
|
object code interpreter used to run it.
|
||||||
|
|
||||||
|
The "Corresponding Source" for a work in object code form means all
|
||||||
|
the source code needed to generate, install, and (for an executable
|
||||||
|
work) run the object code and to modify the work, including scripts to
|
||||||
|
control those activities. However, it does not include the work's
|
||||||
|
System Libraries, or general-purpose tools or generally available free
|
||||||
|
programs which are used unmodified in performing those activities but
|
||||||
|
which are not part of the work. For example, the Corresponding Source
|
||||||
|
includes interface definition files associated with source files for
|
||||||
|
the work, and the source code for shared libraries and dynamically
|
||||||
|
linked subprograms that the work is specifically designed to require,
|
||||||
|
such as by intimate data communication or control flow between those
|
||||||
|
subprograms and other parts of the work.
|
||||||
|
|
||||||
|
The Corresponding Source need not include anything that users
|
||||||
|
can regenerate automatically from other parts of the Corresponding
|
||||||
|
Source.
|
||||||
|
|
||||||
|
The Corresponding Source for a work in source code form is that
|
||||||
|
same work.
|
||||||
|
|
||||||
|
2. Basic Permissions.
|
||||||
|
|
||||||
|
All rights granted under this License are granted for the term of
|
||||||
|
copyright on the Program, and are irrevocable provided the stated
|
||||||
|
conditions are met. This License explicitly affirms your unlimited
|
||||||
|
permission to run the unmodified Program. The output from running a
|
||||||
|
covered work is covered by this License only if the output, given its
|
||||||
|
content, constitutes a covered work. This License acknowledges your
|
||||||
|
rights of fair use or other equivalent, as provided by copyright law.
|
||||||
|
|
||||||
|
You may make, run and propagate covered works that you do not
|
||||||
|
convey, without conditions so long as your license otherwise remains
|
||||||
|
in force. You may convey covered works to others for the sole purpose
|
||||||
|
of having them make modifications exclusively for you, or provide you
|
||||||
|
with facilities for running those works, provided that you comply with
|
||||||
|
the terms of this License in conveying all material for which you do
|
||||||
|
not control copyright. Those thus making or running the covered works
|
||||||
|
for you must do so exclusively on your behalf, under your direction
|
||||||
|
and control, on terms that prohibit them from making any copies of
|
||||||
|
your copyrighted material outside their relationship with you.
|
||||||
|
|
||||||
|
Conveying under any other circumstances is permitted solely under
|
||||||
|
the conditions stated below. Sublicensing is not allowed; section 10
|
||||||
|
makes it unnecessary.
|
||||||
|
|
||||||
|
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||||
|
|
||||||
|
No covered work shall be deemed part of an effective technological
|
||||||
|
measure under any applicable law fulfilling obligations under article
|
||||||
|
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||||
|
similar laws prohibiting or restricting circumvention of such
|
||||||
|
measures.
|
||||||
|
|
||||||
|
When you convey a covered work, you waive any legal power to forbid
|
||||||
|
circumvention of technological measures to the extent such circumvention
|
||||||
|
is effected by exercising rights under this License with respect to
|
||||||
|
the covered work, and you disclaim any intention to limit operation or
|
||||||
|
modification of the work as a means of enforcing, against the work's
|
||||||
|
users, your or third parties' legal rights to forbid circumvention of
|
||||||
|
technological measures.
|
||||||
|
|
||||||
|
4. Conveying Verbatim Copies.
|
||||||
|
|
||||||
|
You may convey verbatim copies of the Program's source code as you
|
||||||
|
receive it, in any medium, provided that you conspicuously and
|
||||||
|
appropriately publish on each copy an appropriate copyright notice;
|
||||||
|
keep intact all notices stating that this License and any
|
||||||
|
non-permissive terms added in accordance with section 7 apply to the
|
||||||
|
code; keep intact all notices of the absence of any warranty; and
|
||||||
|
give all recipients a copy of this License along with the Program.
|
||||||
|
|
||||||
|
You may charge any price or no price for each copy that you convey,
|
||||||
|
and you may offer support or warranty protection for a fee.
|
||||||
|
|
||||||
|
5. Conveying Modified Source Versions.
|
||||||
|
|
||||||
|
You may convey a work based on the Program, or the modifications to
|
||||||
|
produce it from the Program, in the form of source code under the
|
||||||
|
terms of section 4, provided that you also meet all of these conditions:
|
||||||
|
|
||||||
|
a) The work must carry prominent notices stating that you modified
|
||||||
|
it, and giving a relevant date.
|
||||||
|
|
||||||
|
b) The work must carry prominent notices stating that it is
|
||||||
|
released under this License and any conditions added under
|
||||||
|
section 7. This notice modifies the requirement in section 4 to
|
||||||
|
"keep intact all notices".
|
||||||
|
|
||||||
|
c) You must license the entire work, as a whole, under this
|
||||||
|
License to anyone who comes into possession of a copy. This
|
||||||
|
License will therefore apply, along with any applicable section 7
|
||||||
|
additional terms, to the whole of the work, and all its parts,
|
||||||
|
regardless of how they are packaged. This License gives no
|
||||||
|
permission to license the work in any other way, but it does not
|
||||||
|
invalidate such permission if you have separately received it.
|
||||||
|
|
||||||
|
d) If the work has interactive user interfaces, each must display
|
||||||
|
Appropriate Legal Notices; however, if the Program has
|
||||||
|
interactive interfaces that do not display Appropriate Legal
|
||||||
|
Notices, your work need not make them do so.
|
||||||
|
|
||||||
|
A compilation of a covered work with other separate and independent
|
||||||
|
works, which are not by their nature extensions of the covered work,
|
||||||
|
and which are not combined with it such as to form a larger program,
|
||||||
|
in or on a volume of a storage or distribution medium, is called an
|
||||||
|
"aggregate" if the compilation and its resulting copyright are not
|
||||||
|
used to limit the access or legal rights of the compilation's users
|
||||||
|
beyond what the individual works permit. Inclusion of a covered work
|
||||||
|
in an aggregate does not cause this License to apply to the other
|
||||||
|
parts of the aggregate.
|
||||||
|
|
||||||
|
6. Conveying Non-Source Forms.
|
||||||
|
|
||||||
|
You may convey a covered work in object code form under the terms
|
||||||
|
of sections 4 and 5, provided that you also convey the
|
||||||
|
machine-readable Corresponding Source under the terms of this License,
|
||||||
|
in one of these ways:
|
||||||
|
|
||||||
|
a) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by the
|
||||||
|
Corresponding Source fixed on a durable physical medium
|
||||||
|
customarily used for software interchange.
|
||||||
|
|
||||||
|
b) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by a
|
||||||
|
written offer, valid for at least three years and valid for as
|
||||||
|
long as you offer spare parts or customer support for that
|
||||||
|
product model, to give anyone who possesses the object code
|
||||||
|
either (1) a copy of the Corresponding Source for all the
|
||||||
|
software in the product that is covered by this License, on a
|
||||||
|
durable physical medium customarily used for software
|
||||||
|
interchange, for a price no more than your reasonable cost of
|
||||||
|
physically performing this conveying of source, or (2) access to
|
||||||
|
copy the Corresponding Source from a network server at no charge.
|
||||||
|
|
||||||
|
c) Convey individual copies of the object code with a copy of the
|
||||||
|
written offer to provide the Corresponding Source. This
|
||||||
|
alternative is allowed only occasionally and noncommercially, and
|
||||||
|
only if you received the object code with such an offer, in
|
||||||
|
accord with subsection 6b.
|
||||||
|
|
||||||
|
d) Convey the object code by offering access from a designated
|
||||||
|
place (gratis or for a fee), and offer equivalent access to the
|
||||||
|
Corresponding Source in the same way through a different server
|
||||||
|
at no charge. You need not require recipients to copy the
|
||||||
|
Corresponding Source along with the object code. If the place to
|
||||||
|
copy the object code is a network server, the Corresponding
|
||||||
|
Source may be on a different server (operated by you or a third
|
||||||
|
party) that supports equivalent copying facilities, provided you
|
||||||
|
maintain clear directions next to the object code saying where
|
||||||
|
the Corresponding Source is located. Regardless of what server
|
||||||
|
hosts the Corresponding Source, you remain obligated to ensure
|
||||||
|
that it is available for as long as needed to satisfy these
|
||||||
|
requirements.
|
||||||
|
|
||||||
|
e) Convey the object code using peer-to-peer transmission, provided
|
||||||
|
you inform other peers where the object code and Corresponding
|
||||||
|
Source of the work are being offered to the general public at no
|
||||||
|
charge under subsection 6d.
|
||||||
|
|
||||||
|
A separable portion of the object code, whose source code is excluded
|
||||||
|
from the Corresponding Source as a System Library, need not be
|
||||||
|
included in conveying the object code work.
|
||||||
|
|
||||||
|
A "User Product" is either (1) a "consumer product", which means any
|
||||||
|
tangible personal property which is normally used for personal, family,
|
||||||
|
or household purposes, or (2) anything designed or sold for incorporation
|
||||||
|
into a dwelling. In determining whether a product is a consumer product,
|
||||||
|
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||||
|
product received by a particular user, "normally used" refers to a
|
||||||
|
typical or common use of that class of product, regardless of the status
|
||||||
|
of the particular user or of the way in which the particular user
|
||||||
|
actually uses, or expects or is expected to use, the product. A product
|
||||||
|
is a consumer product regardless of whether the product has substantial
|
||||||
|
commercial, industrial or non-consumer uses, unless such uses represent
|
||||||
|
the only significant mode of use of the product.
|
||||||
|
|
||||||
|
"Installation Information" for a User Product means any methods,
|
||||||
|
procedures, authorization keys, or other information required to install
|
||||||
|
and execute modified versions of a covered work in that User Product from
|
||||||
|
a modified version of its Corresponding Source. The information must
|
||||||
|
suffice to ensure that the continued functioning of the modified object
|
||||||
|
code is in no case prevented or interfered with solely because
|
||||||
|
modification has been made.
|
||||||
|
|
||||||
|
If you convey an object code work under this section in, or with, or
|
||||||
|
specifically for use in, a User Product, and the conveying occurs as
|
||||||
|
part of a transaction in which the right of possession and use of the
|
||||||
|
User Product is transferred to the recipient in perpetuity or for a
|
||||||
|
fixed term (regardless of how the transaction is characterized), the
|
||||||
|
Corresponding Source conveyed under this section must be accompanied
|
||||||
|
by the Installation Information. But this requirement does not apply
|
||||||
|
if neither you nor any third party retains the ability to install
|
||||||
|
modified object code on the User Product (for example, the work has
|
||||||
|
been installed in ROM).
|
||||||
|
|
||||||
|
The requirement to provide Installation Information does not include a
|
||||||
|
requirement to continue to provide support service, warranty, or updates
|
||||||
|
for a work that has been modified or installed by the recipient, or for
|
||||||
|
the User Product in which it has been modified or installed. Access to
|
||||||
|
a network may be denied when the modification itself materially and
|
||||||
|
adversely affects the operation of the network or violates the rules and
|
||||||
|
protocols for communication across the network.
|
||||||
|
|
||||||
|
Corresponding Source conveyed, and Installation Information provided,
|
||||||
|
in accord with this section must be in a format that is publicly
|
||||||
|
documented (and with an implementation available to the public in
|
||||||
|
source code form), and must require no special password or key for
|
||||||
|
unpacking, reading or copying.
|
||||||
|
|
||||||
|
7. Additional Terms.
|
||||||
|
|
||||||
|
"Additional permissions" are terms that supplement the terms of this
|
||||||
|
License by making exceptions from one or more of its conditions.
|
||||||
|
Additional permissions that are applicable to the entire Program shall
|
||||||
|
be treated as though they were included in this License, to the extent
|
||||||
|
that they are valid under applicable law. If additional permissions
|
||||||
|
apply only to part of the Program, that part may be used separately
|
||||||
|
under those permissions, but the entire Program remains governed by
|
||||||
|
this License without regard to the additional permissions.
|
||||||
|
|
||||||
|
When you convey a copy of a covered work, you may at your option
|
||||||
|
remove any additional permissions from that copy, or from any part of
|
||||||
|
it. (Additional permissions may be written to require their own
|
||||||
|
removal in certain cases when you modify the work.) You may place
|
||||||
|
additional permissions on material, added by you to a covered work,
|
||||||
|
for which you have or can give appropriate copyright permission.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, for material you
|
||||||
|
add to a covered work, you may (if authorized by the copyright holders of
|
||||||
|
that material) supplement the terms of this License with terms:
|
||||||
|
|
||||||
|
a) Disclaiming warranty or limiting liability differently from the
|
||||||
|
terms of sections 15 and 16 of this License; or
|
||||||
|
|
||||||
|
b) Requiring preservation of specified reasonable legal notices or
|
||||||
|
author attributions in that material or in the Appropriate Legal
|
||||||
|
Notices displayed by works containing it; or
|
||||||
|
|
||||||
|
c) Prohibiting misrepresentation of the origin of that material, or
|
||||||
|
requiring that modified versions of such material be marked in
|
||||||
|
reasonable ways as different from the original version; or
|
||||||
|
|
||||||
|
d) Limiting the use for publicity purposes of names of licensors or
|
||||||
|
authors of the material; or
|
||||||
|
|
||||||
|
e) Declining to grant rights under trademark law for use of some
|
||||||
|
trade names, trademarks, or service marks; or
|
||||||
|
|
||||||
|
f) Requiring indemnification of licensors and authors of that
|
||||||
|
material by anyone who conveys the material (or modified versions of
|
||||||
|
it) with contractual assumptions of liability to the recipient, for
|
||||||
|
any liability that these contractual assumptions directly impose on
|
||||||
|
those licensors and authors.
|
||||||
|
|
||||||
|
All other non-permissive additional terms are considered "further
|
||||||
|
restrictions" within the meaning of section 10. If the Program as you
|
||||||
|
received it, or any part of it, contains a notice stating that it is
|
||||||
|
governed by this License along with a term that is a further
|
||||||
|
restriction, you may remove that term. If a license document contains
|
||||||
|
a further restriction but permits relicensing or propagation under
|
||||||
|
this License, you may add to a covered work material governed by the
|
||||||
|
terms of that license document, provided that the further restriction
|
||||||
|
does not survive such relicensing or propagation.
|
||||||
|
|
||||||
|
If you add terms to a covered work in accordance with this section,
|
||||||
|
you must place, in the relevant source files, a statement of the
|
||||||
|
additional terms that apply to those files, or a notice indicating
|
||||||
|
where to find the applicable terms.
|
||||||
|
|
||||||
|
Additional terms, permissive or non-permissive, may be stated in the
|
||||||
|
form of a separately written license, or stated as exceptions;
|
||||||
|
the above requirements apply in either case.
|
||||||
|
|
||||||
|
8. Termination.
|
||||||
|
|
||||||
|
You may not propagate or modify a covered work except as expressly
|
||||||
|
provided under this License. Any attempt otherwise to propagate or
|
||||||
|
modify it is void, and will automatically terminate your rights under
|
||||||
|
this License (including any patent licenses granted under the third
|
||||||
|
paragraph of section 11).
|
||||||
|
|
||||||
|
However, if you cease all violation of this License, then your
|
||||||
|
license from a particular copyright holder is reinstated (a)
|
||||||
|
provisionally, unless and until the copyright holder explicitly and
|
||||||
|
finally terminates your license, and (b) permanently, if the copyright
|
||||||
|
holder fails to notify you of the violation by some reasonable means
|
||||||
|
prior to 60 days after the cessation.
|
||||||
|
|
||||||
|
Moreover, your license from a particular copyright holder is
|
||||||
|
reinstated permanently if the copyright holder notifies you of the
|
||||||
|
violation by some reasonable means, this is the first time you have
|
||||||
|
received notice of violation of this License (for any work) from that
|
||||||
|
copyright holder, and you cure the violation prior to 30 days after
|
||||||
|
your receipt of the notice.
|
||||||
|
|
||||||
|
Termination of your rights under this section does not terminate the
|
||||||
|
licenses of parties who have received copies or rights from you under
|
||||||
|
this License. If your rights have been terminated and not permanently
|
||||||
|
reinstated, you do not qualify to receive new licenses for the same
|
||||||
|
material under section 10.
|
||||||
|
|
||||||
|
9. Acceptance Not Required for Having Copies.
|
||||||
|
|
||||||
|
You are not required to accept this License in order to receive or
|
||||||
|
run a copy of the Program. Ancillary propagation of a covered work
|
||||||
|
occurring solely as a consequence of using peer-to-peer transmission
|
||||||
|
to receive a copy likewise does not require acceptance. However,
|
||||||
|
nothing other than this License grants you permission to propagate or
|
||||||
|
modify any covered work. These actions infringe copyright if you do
|
||||||
|
not accept this License. Therefore, by modifying or propagating a
|
||||||
|
covered work, you indicate your acceptance of this License to do so.
|
||||||
|
|
||||||
|
10. Automatic Licensing of Downstream Recipients.
|
||||||
|
|
||||||
|
Each time you convey a covered work, the recipient automatically
|
||||||
|
receives a license from the original licensors, to run, modify and
|
||||||
|
propagate that work, subject to this License. You are not responsible
|
||||||
|
for enforcing compliance by third parties with this License.
|
||||||
|
|
||||||
|
An "entity transaction" is a transaction transferring control of an
|
||||||
|
organization, or substantially all assets of one, or subdividing an
|
||||||
|
organization, or merging organizations. If propagation of a covered
|
||||||
|
work results from an entity transaction, each party to that
|
||||||
|
transaction who receives a copy of the work also receives whatever
|
||||||
|
licenses to the work the party's predecessor in interest had or could
|
||||||
|
give under the previous paragraph, plus a right to possession of the
|
||||||
|
Corresponding Source of the work from the predecessor in interest, if
|
||||||
|
the predecessor has it or can get it with reasonable efforts.
|
||||||
|
|
||||||
|
You may not impose any further restrictions on the exercise of the
|
||||||
|
rights granted or affirmed under this License. For example, you may
|
||||||
|
not impose a license fee, royalty, or other charge for exercise of
|
||||||
|
rights granted under this License, and you may not initiate litigation
|
||||||
|
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||||
|
any patent claim is infringed by making, using, selling, offering for
|
||||||
|
sale, or importing the Program or any portion of it.
|
||||||
|
|
||||||
|
11. Patents.
|
||||||
|
|
||||||
|
A "contributor" is a copyright holder who authorizes use under this
|
||||||
|
License of the Program or a work on which the Program is based. The
|
||||||
|
work thus licensed is called the contributor's "contributor version".
|
||||||
|
|
||||||
|
A contributor's "essential patent claims" are all patent claims
|
||||||
|
owned or controlled by the contributor, whether already acquired or
|
||||||
|
hereafter acquired, that would be infringed by some manner, permitted
|
||||||
|
by this License, of making, using, or selling its contributor version,
|
||||||
|
but do not include claims that would be infringed only as a
|
||||||
|
consequence of further modification of the contributor version. For
|
||||||
|
purposes of this definition, "control" includes the right to grant
|
||||||
|
patent sublicenses in a manner consistent with the requirements of
|
||||||
|
this License.
|
||||||
|
|
||||||
|
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||||
|
patent license under the contributor's essential patent claims, to
|
||||||
|
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||||
|
propagate the contents of its contributor version.
|
||||||
|
|
||||||
|
In the following three paragraphs, a "patent license" is any express
|
||||||
|
agreement or commitment, however denominated, not to enforce a patent
|
||||||
|
(such as an express permission to practice a patent or covenant not to
|
||||||
|
sue for patent infringement). To "grant" such a patent license to a
|
||||||
|
party means to make such an agreement or commitment not to enforce a
|
||||||
|
patent against the party.
|
||||||
|
|
||||||
|
If you convey a covered work, knowingly relying on a patent license,
|
||||||
|
and the Corresponding Source of the work is not available for anyone
|
||||||
|
to copy, free of charge and under the terms of this License, through a
|
||||||
|
network server or other readily accessible means, then you must either
|
||||||
|
(1) cause the Corresponding Source to be so available, or (2) arrange
|
||||||
|
to deprive yourself of the benefit of the patent license for this
|
||||||
|
particular work, or (3) arrange, in a manner consistent with the
|
||||||
|
requirements of this License, to extend the patent license to
|
||||||
|
downstream recipients. "Knowingly relying" means you have actual
|
||||||
|
knowledge that, but for the patent license, your conveying the covered
|
||||||
|
work in a country, or your recipient's use of the covered work in a
|
||||||
|
country, would infringe one or more identifiable patents in that
|
||||||
|
country that you have reason to believe are valid.
|
||||||
|
|
||||||
|
If, pursuant to or in connection with a single transaction or
|
||||||
|
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||||
|
covered work, and grant a patent license to some of the parties
|
||||||
|
receiving the covered work authorizing them to use, propagate, modify
|
||||||
|
or convey a specific copy of the covered work, then the patent license
|
||||||
|
you grant is automatically extended to all recipients of the covered
|
||||||
|
work and works based on it.
|
||||||
|
|
||||||
|
A patent license is "discriminatory" if it does not include within
|
||||||
|
the scope of its coverage, prohibits the exercise of, or is
|
||||||
|
conditioned on the non-exercise of one or more of the rights that are
|
||||||
|
specifically granted under this License. You may not convey a covered
|
||||||
|
work if you are a party to an arrangement with a third party that is
|
||||||
|
in the business of distributing software, under which you make payment
|
||||||
|
to the third party based on the extent of your activity of conveying
|
||||||
|
the work, and under which the third party grants, to any of the
|
||||||
|
parties who would receive the covered work from you, a discriminatory
|
||||||
|
patent license (a) in connection with copies of the covered work
|
||||||
|
conveyed by you (or copies made from those copies), or (b) primarily
|
||||||
|
for and in connection with specific products or compilations that
|
||||||
|
contain the covered work, unless you entered into that arrangement,
|
||||||
|
or that patent license was granted, prior to 28 March 2007.
|
||||||
|
|
||||||
|
Nothing in this License shall be construed as excluding or limiting
|
||||||
|
any implied license or other defenses to infringement that may
|
||||||
|
otherwise be available to you under applicable patent law.
|
||||||
|
|
||||||
|
12. No Surrender of Others' Freedom.
|
||||||
|
|
||||||
|
If conditions are imposed on you (whether by court order, agreement or
|
||||||
|
otherwise) that contradict the conditions of this License, they do not
|
||||||
|
excuse you from the conditions of this License. If you cannot convey a
|
||||||
|
covered work so as to satisfy simultaneously your obligations under this
|
||||||
|
License and any other pertinent obligations, then as a consequence you
|
||||||
|
may not convey it at all. For example, if you agree to terms that
|
||||||
|
obligate you to collect a royalty for further conveying from those to
|
||||||
|
whom you convey the Program, the only way you could satisfy both those
|
||||||
|
terms and this License would be to refrain entirely from conveying the
|
||||||
|
Program.
|
||||||
|
|
||||||
|
13. Use with the GNU Affero General Public License.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, you have
|
||||||
|
permission to link or combine any covered work with a work licensed
|
||||||
|
under version 3 of the GNU Affero General Public License into a single
|
||||||
|
combined work, and to convey the resulting work. The terms of this
|
||||||
|
License will continue to apply to the part which is the covered work,
|
||||||
|
but the special requirements of the GNU Affero General Public License,
|
||||||
|
section 13, concerning interaction through a network will apply to the
|
||||||
|
combination as such.
|
||||||
|
|
||||||
|
14. Revised Versions of this License.
|
||||||
|
|
||||||
|
The Free Software Foundation may publish revised and/or new versions
|
||||||
|
of the GNU General Public License from time to time. Such new versions
|
||||||
|
will be similar in spirit to the present version, but may differ in
|
||||||
|
detail to address new problems or concerns.
|
||||||
|
|
||||||
|
Each version is given a distinguishing version number. If the
|
||||||
|
Program specifies that a certain numbered version of the GNU General
|
||||||
|
Public License "or any later version" applies to it, you have the
|
||||||
|
option of following the terms and conditions either of that numbered
|
||||||
|
version or of any later version published by the Free Software
|
||||||
|
Foundation. If the Program does not specify a version number of the
|
||||||
|
GNU General Public License, you may choose any version ever published
|
||||||
|
by the Free Software Foundation.
|
||||||
|
|
||||||
|
If the Program specifies that a proxy can decide which future
|
||||||
|
versions of the GNU General Public License can be used, that proxy's
|
||||||
|
public statement of acceptance of a version permanently authorizes you
|
||||||
|
to choose that version for the Program.
|
||||||
|
|
||||||
|
Later license versions may give you additional or different
|
||||||
|
permissions. However, no additional obligations are imposed on any
|
||||||
|
author or copyright holder as a result of your choosing to follow a
|
||||||
|
later version.
|
||||||
|
|
||||||
|
15. Disclaimer of Warranty.
|
||||||
|
|
||||||
|
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||||
|
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||||
|
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT
|
||||||
|
WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT
|
||||||
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||||
|
PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE
|
||||||
|
OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU
|
||||||
|
ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||||
|
|
||||||
|
16. Limitation of Liability.
|
||||||
|
|
||||||
|
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||||
|
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||||
|
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING
|
||||||
|
ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF
|
||||||
|
THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO
|
||||||
|
LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||||
|
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY
|
||||||
|
OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF
|
||||||
|
THE POSSIBILITY OF SUCH DAMAGES.
|
||||||
|
|
||||||
|
17. Interpretation of Sections 15 and 16.
|
||||||
|
|
||||||
|
If the disclaimer of warranty and limitation of liability provided
|
||||||
|
above cannot be given local legal effect according to their terms,
|
||||||
|
reviewing courts shall apply local law that most closely approximates
|
||||||
|
an absolute waiver of all civil liability in connection with the
|
||||||
|
Program, unless a warranty or assumption of liability accompanies a
|
||||||
|
copy of the Program in return for a fee.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
How to Apply These Terms to Your New Programs
|
||||||
|
|
||||||
|
If you develop a new program, and you want it to be of the greatest
|
||||||
|
possible use to the public, the best way to achieve this is to make it
|
||||||
|
free software which everyone can redistribute and change under these terms.
|
||||||
|
|
||||||
|
To do so, attach the following notices to the program. It is safest
|
||||||
|
to attach them to the start of each source file to most effectively
|
||||||
|
state the absence of warranty; and each file should have at least the
|
||||||
|
"copyright" line and a pointer to where the full notice is found.
|
||||||
|
|
||||||
|
<one line to give the program's name and a brief idea of what it does.>
|
||||||
|
Copyright (C) <year> <name of author>
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
Also add information on how to contact you by electronic and paper mail.
|
||||||
|
|
||||||
|
If the program does terminal interaction, make it output a short
|
||||||
|
notice like this when it starts in an interactive mode:
|
||||||
|
|
||||||
|
<program> Copyright (C) <year> <name of author>
|
||||||
|
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||||
|
This is free software, and you are welcome to redistribute it
|
||||||
|
under certain conditions; type `show c' for details.
|
||||||
|
|
||||||
|
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||||
|
parts of the General Public License. Of course, your program's commands
|
||||||
|
might be different; for a GUI interface, you would use an "about box".
|
||||||
|
|
||||||
|
You should also get your employer (if you work as a programmer) or school,
|
||||||
|
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||||
|
For more information on this, and how to apply and follow the GNU GPL, see
|
||||||
|
<https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
The GNU General Public License does not permit incorporating your program
|
||||||
|
into proprietary programs. If your program is a subroutine library, you
|
||||||
|
may consider it more useful to permit linking proprietary applications
|
||||||
|
with the library. If this is what you want to do, use the GNU Lesser
|
||||||
|
General Public License instead of this License. But first, please read
|
||||||
|
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
||||||
@@ -2,13 +2,16 @@
|
|||||||
<img src="app/assets/logo.png" alt="ICRA" width="140"/>
|
<img src="app/assets/logo.png" alt="ICRA" width="140"/>
|
||||||
<div>
|
<div>
|
||||||
<strong>Interactive Color Range Analyzer (ICRA)</strong><br/>
|
<strong>Interactive Color Range Analyzer (ICRA)</strong><br/>
|
||||||
A fully-featured, PySide6-powered desktop application for precise color matching, image analysis, and statistics generation.
|
A professional desktop application for high-precision color matching, clustering analysis, and batch statistics generation.
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
- **High-Performance Image Processing:** Native, vectorized NumPy operations for lightning-fast HSV conversion and color matching.
|
- **High-Performance Image Processing:** Native, vectorized NumPy operations for lightning-fast HSV conversion and color matching.
|
||||||
- **Batch Folder Processing:** Load a folder of images and instantly export an aggregated `icra_stats.csv` with localized formatting (dot or comma decimals depending on your language).
|
- **Automatic Background Exclusion:** Intelligently ignores background pixels (configurable in `config.toml`) to ensure they don't interfere with your analysis.
|
||||||
|
- **Grouping Score (Clustering):** A high-performance 9x9 box-sum algorithm that rewards solid "splashes" of color and penalizes thin lines or fragmented noise.
|
||||||
|
- **Batch Processing & Customizable Export:** Load a folder of images and instantly export `icra_stats.csv` and `icra_settings.json`. Features a dedicated **Weighting Dialog** to customize the impact of each core component.
|
||||||
|
- **Import/Export Settings:** Save your HSV ranges, exclusion zones, and weighting preferences to a JSON file and reload them later for consistent analysis across different sessions.
|
||||||
- **Eyedropper Tool:** Quickly pick target matching colors directly from the image canvas.
|
- **Eyedropper Tool:** Quickly pick target matching colors directly from the image canvas.
|
||||||
- **Advanced Selection:** Support for exclusion zones (rectangles and free-draw polygons) overlaid on the image, all dynamically rendered via `QGraphicsView`.
|
- **Advanced Selection:** Support for exclusion zones (rectangles and free-draw polygons) overlaid on the image, all dynamically rendered via `QGraphicsView`.
|
||||||
- **Modern UI & UX:**
|
- **Modern UI & UX:**
|
||||||
@@ -18,6 +21,37 @@
|
|||||||
- Keyboard shortcuts for rapid workflow.
|
- Keyboard shortcuts for rapid workflow.
|
||||||
- **Configurable:** Uses `config.toml` to drive everything from overlay matching colors to default sliders and application language (`en`/`de`).
|
- **Configurable:** Uses `config.toml` to drive everything from overlay matching colors to default sliders and application language (`en`/`de`).
|
||||||
|
|
||||||
|
## Core Concepts
|
||||||
|
|
||||||
|
### 1. HSV Color Matching
|
||||||
|
Instead of simple RGB, ICRA uses the **HSV (Hue, Saturation, Value)** color space. This allows for more intuitive color selection:
|
||||||
|
- **Hue (0-360°):** The base "color" (Red, Green, Blue, etc.).
|
||||||
|
- **Saturation (0-100%):** The intensity or "vibrancy".
|
||||||
|
- **Value (0-100%):** The brightness.
|
||||||
|
Matching is performed by checking if each pixel's HSV values fall within your defined ranges.
|
||||||
|
|
||||||
|
### 2. Scoring Components
|
||||||
|
The **Composite Score** is calculated weighted by your preferences:
|
||||||
|
- **Match (Keep):** Percentage of matching pixels *after* excluding your manual shapes and background areas.
|
||||||
|
- **Match (All):** Percentage of matching pixels across the entire image.
|
||||||
|
- **Brightness Score:** Calculated from the average brightness of the "Keep" areas. If "Prefer Dark" is ON, lower brightness results in a higher score.
|
||||||
|
- **Grouping Score:** Uses a 9x9 box-sum density check. Higher values indicate that matching pixels are clustered into solid blocks rather than scattered noise.
|
||||||
|
|
||||||
|
### 3. Background Filtering
|
||||||
|
To ensure accurate statistics, ICRA automatically filters out the image background (e.g., the dark grey/black backdrop in weapon screenshots). These settings are fully configurable in `config.toml`, allowing you to adjust the target color and the tolerance required for exclusion.
|
||||||
|
|
||||||
|
### 4. Exclusion Zones
|
||||||
|
Use the **Exclusion Tool** to draw rectangles or polygons over areas you want to ignore. This is essential for focusing your analysis on specific parts of a complex image while ignoring background noise or irrelevant details.
|
||||||
|
|
||||||
|
## Typical Workflow
|
||||||
|
|
||||||
|
1. **Load Data:** Drag and drop a folder or use the `File` menu to load your images.
|
||||||
|
2. **Pick Color:** Use the Eyedropper tool to select your target color directly from the image.
|
||||||
|
3. **Refine HSV:** Fine-tune the Hue, Saturation, and Value sliders to perfect the mask.
|
||||||
|
4. **Draw Exclusions:** Add exclusion shapes to ignore parts of the image that shouldn't be counted.
|
||||||
|
5. **Export:** Click `Export Folder Stats`. Define your weights (e.g., prioritize the Grouping Score if you want coherent splashes) and save your results.
|
||||||
|
6. **Persistent Settings:** Use `File -> Export Settings` to save your configuration, or `File -> Import Settings` to restore a previous setup.
|
||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
- Python 3.11+
|
- Python 3.11+
|
||||||
- [uv](https://github.com/astral-sh/uv) for dependency management
|
- [uv](https://github.com/astral-sh/uv) for dependency management
|
||||||
@@ -42,16 +76,21 @@ uv run pytest tests/ -v
|
|||||||
## Project Layout
|
## Project Layout
|
||||||
```
|
```
|
||||||
app/
|
app/
|
||||||
assets/ # Shared branding
|
assets/ # Icons and branding
|
||||||
lang/ # Localization strings (TOML format)
|
lang/ # Translations (TOML)
|
||||||
logic/ # Configuration loading and application constants
|
qt/ # UI implementation and NumPy processing
|
||||||
qt/ # PySide6 implementation (main_window, custom UI widgets, vectorized image processing)
|
tests/ # Unit tests for core analysis
|
||||||
tests/ # Pytest unit tests
|
config.toml # User-facing configuration
|
||||||
config.toml # Configurable overlay colors, slider defaults
|
main.py # Entry point
|
||||||
main.py # Entry point -> PySide6 launcher
|
LICENSE # GNU GPLv3 terms
|
||||||
```
|
```
|
||||||
|
|
||||||
## Development Notes
|
## Development
|
||||||
- The legacy `Tkinter` codebase has been completely removed in favor of `PySide6`.
|
- **Tests**: Run `uv run pytest tests/ -v` to verify the core logic.
|
||||||
- Quick syntax check: `uv run python -m compileall app main.py`
|
- **Environment**: Managed via `uv`. Run `uv sync` to ensure your environment matches the lockfile.
|
||||||
- Contributions welcome!
|
|
||||||
|
## Contributing
|
||||||
|
Contributions are welcome! Open an issue or submit a pull request.
|
||||||
|
|
||||||
|
## License
|
||||||
|
GPLv3 License. See the LICENSE file for details.
|
||||||
|
|||||||
+16
-4
@@ -12,6 +12,7 @@
|
|||||||
"toolbar.toggle_theme" = "Theme umschalten"
|
"toolbar.toggle_theme" = "Theme umschalten"
|
||||||
"toolbar.open_app_folder" = "Programmordner öffnen"
|
"toolbar.open_app_folder" = "Programmordner öffnen"
|
||||||
"toolbar.prefer_dark" = "Dunkelheit bevorzugen"
|
"toolbar.prefer_dark" = "Dunkelheit bevorzugen"
|
||||||
|
"toolbar.exclude_bg" = "Hintergrund ausblenden ({color})"
|
||||||
"status.no_file" = "Keine Datei geladen."
|
"status.no_file" = "Keine Datei geladen."
|
||||||
"status.defaults_restored" = "Standardwerte aktiv."
|
"status.defaults_restored" = "Standardwerte aktiv."
|
||||||
"status.free_draw_enabled" = "Freihand-Ausschluss aktiviert."
|
"status.free_draw_enabled" = "Freihand-Ausschluss aktiviert."
|
||||||
@@ -39,13 +40,15 @@
|
|||||||
"sliders.hue_min" = "Hue Min (°)"
|
"sliders.hue_min" = "Hue Min (°)"
|
||||||
"sliders.hue_max" = "Hue Max (°)"
|
"sliders.hue_max" = "Hue Max (°)"
|
||||||
"sliders.sat_min" = "Sättigung Min (%)"
|
"sliders.sat_min" = "Sättigung Min (%)"
|
||||||
|
"sliders.sat_max" = "Sättigung Max (%)"
|
||||||
"sliders.val_min" = "Helligkeit Min (%)"
|
"sliders.val_min" = "Helligkeit Min (%)"
|
||||||
"sliders.val_max" = "Helligkeit Max (%)"
|
"sliders.val_max" = "Helligkeit Max (%)"
|
||||||
"sliders.alpha" = "Overlay Alpha"
|
"sliders.alpha" = "Overlay Alpha"
|
||||||
"stats.placeholder" = "Markierungen (mit Ausschlüssen): —"
|
"stats.placeholder" = "Markierungen (mit Ausschlüssen): —"
|
||||||
"stats.summary" = "Score: {score:.2f}% | Markierungen (m. Ausschl.): {with_pct:.2f}% | Markierungen: {without_pct:.2f}% | {brightness_label}: {brightness:.1f}% | Ausgeschlossen: {excluded_pct:.2f}%"
|
"stats.summary" = "Wertung: {score:.2f}% | Treffer (mit Exkl.): {with_pct:.2f}% | Treffer: {without_pct:.2f}% | {brightness_label}: {brightness:.1f}% | Gruppierung: {grouping:.1f}% | Ausgeschlossen: {excluded_pct:.2f}%"
|
||||||
"stats.brightness_label" = "Helligkeit"
|
"stats.brightness_label" = "Helligkeit"
|
||||||
"stats.darkness_label" = "Dunkelheit"
|
"stats.darkness_label" = "Dunkelheit"
|
||||||
|
"stats.grouping_label" = "Gruppierung"
|
||||||
"menu.copy" = "Kopieren"
|
"menu.copy" = "Kopieren"
|
||||||
"dialog.info_title" = "Info"
|
"dialog.info_title" = "Info"
|
||||||
"dialog.error_title" = "Fehler"
|
"dialog.error_title" = "Fehler"
|
||||||
@@ -81,10 +84,19 @@
|
|||||||
"menu.view" = "Ansicht"
|
"menu.view" = "Ansicht"
|
||||||
"menu.tools" = "Werkzeuge"
|
"menu.tools" = "Werkzeuge"
|
||||||
|
|
||||||
"toolbar.pull_patterns" = "Muster-Bilder herunterladen"
|
"toolbar.pull_patterns" = "Muster-Bilder laden"
|
||||||
"dialog.puller_title" = "Muster-Bilder herunterladen"
|
"dialog.puller_title" = "Muster-Bilder laden"
|
||||||
"dialog.puller_instruction" = "CSGOSkins.gg Artikel-URL einfügen:"
|
"dialog.puller_instruction" = "CSGOSkins.gg Item-URL einfügen:"
|
||||||
"dialog.puller_start" = "Download starten"
|
"dialog.puller_start" = "Download starten"
|
||||||
"dialog.puller_cancel" = "Abbrechen"
|
"dialog.puller_cancel" = "Abbrechen"
|
||||||
"dialog.puller_invalid_url" = "Ungültiges URL-Format."
|
"dialog.puller_invalid_url" = "Ungültiges URL-Format."
|
||||||
"dialog.puller_success" = "Alle Muster erfolgreich heruntergeladen!"
|
"dialog.puller_success" = "Alle Muster erfolgreich heruntergeladen!"
|
||||||
|
|
||||||
|
"dialog.weighting_title" = "Export-Gewichtung & Präferenz"
|
||||||
|
"dialog.weighting_instruction" = "Gewichtung der Komponenten festlegen (Summe muss 100% sein):"
|
||||||
|
"dialog.weight_match_all" = "Treffer (Alle) %"
|
||||||
|
"dialog.weight_match_keep" = "Treffer (Behalten) %"
|
||||||
|
"dialog.weight_brightness" = "Helligkeit/Dunkelheit %"
|
||||||
|
"dialog.weight_grouping" = "Gruppierung %"
|
||||||
|
"dialog.total_weight" = "Gesamt:"
|
||||||
|
"dialog.weight_error" = "Die Summe muss genau 100% sein (aktuell {total}%)."
|
||||||
|
|||||||
+13
-1
@@ -12,6 +12,7 @@
|
|||||||
"toolbar.toggle_theme" = "Toggle theme"
|
"toolbar.toggle_theme" = "Toggle theme"
|
||||||
"toolbar.open_app_folder" = "Open application folder"
|
"toolbar.open_app_folder" = "Open application folder"
|
||||||
"toolbar.prefer_dark" = "Prefer darkness"
|
"toolbar.prefer_dark" = "Prefer darkness"
|
||||||
|
"toolbar.exclude_bg" = "Exclude Background ({color})"
|
||||||
"status.no_file" = "No file loaded."
|
"status.no_file" = "No file loaded."
|
||||||
"status.defaults_restored" = "Defaults restored."
|
"status.defaults_restored" = "Defaults restored."
|
||||||
"status.free_draw_enabled" = "Free-draw exclusion mode enabled."
|
"status.free_draw_enabled" = "Free-draw exclusion mode enabled."
|
||||||
@@ -39,13 +40,15 @@
|
|||||||
"sliders.hue_min" = "Hue min (°)"
|
"sliders.hue_min" = "Hue min (°)"
|
||||||
"sliders.hue_max" = "Hue max (°)"
|
"sliders.hue_max" = "Hue max (°)"
|
||||||
"sliders.sat_min" = "Saturation min (%)"
|
"sliders.sat_min" = "Saturation min (%)"
|
||||||
|
"sliders.sat_max" = "Saturation max (%)"
|
||||||
"sliders.val_min" = "Value min (%)"
|
"sliders.val_min" = "Value min (%)"
|
||||||
"sliders.val_max" = "Value max (%)"
|
"sliders.val_max" = "Value max (%)"
|
||||||
"sliders.alpha" = "Overlay alpha"
|
"sliders.alpha" = "Overlay alpha"
|
||||||
"stats.placeholder" = "Matches (with exclusions): —"
|
"stats.placeholder" = "Matches (with exclusions): —"
|
||||||
"stats.summary" = "Score: {score:.2f}% | Matches (w/ excl.): {with_pct:.2f}% | Matches: {without_pct:.2f}% | {brightness_label}: {brightness:.1f}% | Excluded: {excluded_pct:.2f}%"
|
"stats.summary" = "Score: {score:.2f}% | Matches (w/ excl.): {with_pct:.2f}% | Matches: {without_pct:.2f}% | {brightness_label}: {brightness:.1f}% | Grouping: {grouping:.1f}% | Excluded: {excluded_pct:.2f}%"
|
||||||
"stats.brightness_label" = "Brightness"
|
"stats.brightness_label" = "Brightness"
|
||||||
"stats.darkness_label" = "Darkness"
|
"stats.darkness_label" = "Darkness"
|
||||||
|
"stats.grouping_label" = "Grouping"
|
||||||
"menu.copy" = "Copy"
|
"menu.copy" = "Copy"
|
||||||
"dialog.info_title" = "Info"
|
"dialog.info_title" = "Info"
|
||||||
"dialog.error_title" = "Error"
|
"dialog.error_title" = "Error"
|
||||||
@@ -88,3 +91,12 @@
|
|||||||
"dialog.puller_cancel" = "Cancel"
|
"dialog.puller_cancel" = "Cancel"
|
||||||
"dialog.puller_invalid_url" = "Invalid URL format."
|
"dialog.puller_invalid_url" = "Invalid URL format."
|
||||||
"dialog.puller_success" = "All patterns downloaded successfully!"
|
"dialog.puller_success" = "All patterns downloaded successfully!"
|
||||||
|
|
||||||
|
"dialog.weighting_title" = "Export Weighting & Preference"
|
||||||
|
"dialog.weighting_instruction" = "Set the weighting for each component (total must be 100%):"
|
||||||
|
"dialog.weight_match_all" = "Match (All) %"
|
||||||
|
"dialog.weight_match_keep" = "Match (Keep) %"
|
||||||
|
"dialog.weight_brightness" = "Brightness/Darkness %"
|
||||||
|
"dialog.weight_grouping" = "Grouping %"
|
||||||
|
"dialog.total_weight" = "Total:"
|
||||||
|
"dialog.weight_error" = "Weights must sum exactly to 100% (currently {total}%)."
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ from .constants import (
|
|||||||
IMAGES_DIR,
|
IMAGES_DIR,
|
||||||
LANGUAGE,
|
LANGUAGE,
|
||||||
OVERLAY_COLOR,
|
OVERLAY_COLOR,
|
||||||
|
EXCLUDE_BG_COLOR,
|
||||||
|
EXCLUDE_BG_TOLERANCE,
|
||||||
PREVIEW_MAX_SIZE,
|
PREVIEW_MAX_SIZE,
|
||||||
RESET_EXCLUSIONS_ON_IMAGE_CHANGE,
|
RESET_EXCLUSIONS_ON_IMAGE_CHANGE,
|
||||||
SUPPORTED_IMAGE_EXTENSIONS,
|
SUPPORTED_IMAGE_EXTENSIONS,
|
||||||
@@ -17,6 +19,8 @@ __all__ = [
|
|||||||
"IMAGES_DIR",
|
"IMAGES_DIR",
|
||||||
"LANGUAGE",
|
"LANGUAGE",
|
||||||
"OVERLAY_COLOR",
|
"OVERLAY_COLOR",
|
||||||
|
"EXCLUDE_BG_COLOR",
|
||||||
|
"EXCLUDE_BG_TOLERANCE",
|
||||||
"PREVIEW_MAX_SIZE",
|
"PREVIEW_MAX_SIZE",
|
||||||
"RESET_EXCLUSIONS_ON_IMAGE_CHANGE",
|
"RESET_EXCLUSIONS_ON_IMAGE_CHANGE",
|
||||||
"SUPPORTED_IMAGE_EXTENSIONS",
|
"SUPPORTED_IMAGE_EXTENSIONS",
|
||||||
|
|||||||
+14
-1
@@ -94,7 +94,12 @@ def _extract_language(data: dict[str, Any]) -> str:
|
|||||||
|
|
||||||
_CONFIG_DATA = _load_config_data()
|
_CONFIG_DATA = _load_config_data()
|
||||||
|
|
||||||
_OPTION_DEFAULTS = {"reset_exclusions_on_image_change": False, "overlay_color": "#ff0000"}
|
_OPTION_DEFAULTS = {
|
||||||
|
"reset_exclusions_on_image_change": False,
|
||||||
|
"overlay_color": "#ff0000",
|
||||||
|
"exclude_bg_color": "#1f2937",
|
||||||
|
"exclude_bg_tolerance": 5,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def _extract_options(data: dict[str, Any]) -> dict[str, Any]:
|
def _extract_options(data: dict[str, Any]) -> dict[str, Any]:
|
||||||
@@ -108,6 +113,12 @@ def _extract_options(data: dict[str, Any]) -> dict[str, Any]:
|
|||||||
color = section.get("overlay_color")
|
color = section.get("overlay_color")
|
||||||
if isinstance(color, str) and color.startswith("#") and len(color) in (7, 9):
|
if isinstance(color, str) and color.startswith("#") and len(color) in (7, 9):
|
||||||
result["overlay_color"] = color
|
result["overlay_color"] = color
|
||||||
|
exclude_bg = section.get("exclude_bg_color")
|
||||||
|
if isinstance(exclude_bg, str) and exclude_bg.startswith("#") and len(exclude_bg) in (7, 9):
|
||||||
|
result["exclude_bg_color"] = exclude_bg
|
||||||
|
tolerance = section.get("exclude_bg_tolerance")
|
||||||
|
if isinstance(tolerance, int):
|
||||||
|
result["exclude_bg_tolerance"] = max(0, min(255, tolerance))
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
@@ -116,3 +127,5 @@ LANGUAGE = _extract_language(_CONFIG_DATA)
|
|||||||
OPTIONS = {**_OPTION_DEFAULTS, **_extract_options(_CONFIG_DATA)}
|
OPTIONS = {**_OPTION_DEFAULTS, **_extract_options(_CONFIG_DATA)}
|
||||||
RESET_EXCLUSIONS_ON_IMAGE_CHANGE = OPTIONS["reset_exclusions_on_image_change"]
|
RESET_EXCLUSIONS_ON_IMAGE_CHANGE = OPTIONS["reset_exclusions_on_image_change"]
|
||||||
OVERLAY_COLOR = OPTIONS["overlay_color"]
|
OVERLAY_COLOR = OPTIONS["overlay_color"]
|
||||||
|
EXCLUDE_BG_COLOR = OPTIONS["exclude_bg_color"]
|
||||||
|
EXCLUDE_BG_TOLERANCE = OPTIONS["exclude_bg_tolerance"]
|
||||||
|
|||||||
+3
-1
@@ -46,12 +46,14 @@ def create_application() -> QtWidgets.QApplication:
|
|||||||
def run() -> int:
|
def run() -> int:
|
||||||
"""Run the PySide6 GUI."""
|
"""Run the PySide6 GUI."""
|
||||||
app = create_application()
|
app = create_application()
|
||||||
from app.logic import OVERLAY_COLOR
|
from app.logic import OVERLAY_COLOR, EXCLUDE_BG_COLOR, EXCLUDE_BG_TOLERANCE
|
||||||
window = MainWindow(
|
window = MainWindow(
|
||||||
language=LANGUAGE,
|
language=LANGUAGE,
|
||||||
defaults=DEFAULTS.copy(),
|
defaults=DEFAULTS.copy(),
|
||||||
reset_exclusions=RESET_EXCLUSIONS_ON_IMAGE_CHANGE,
|
reset_exclusions=RESET_EXCLUSIONS_ON_IMAGE_CHANGE,
|
||||||
overlay_color=OVERLAY_COLOR,
|
overlay_color=OVERLAY_COLOR,
|
||||||
|
exclude_bg_color=EXCLUDE_BG_COLOR,
|
||||||
|
exclude_bg_tolerance=EXCLUDE_BG_TOLERANCE,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Respect saved geometry from QSettings; fall back to maximised on first launch
|
# Respect saved geometry from QSettings; fall back to maximised on first launch
|
||||||
|
|||||||
+127
-16
@@ -23,6 +23,7 @@ class Stats:
|
|||||||
matches_excl: int = 0
|
matches_excl: int = 0
|
||||||
total_excl: int = 0
|
total_excl: int = 0
|
||||||
brightness_score: float = 0.0
|
brightness_score: float = 0.0
|
||||||
|
grouping_score: float = 0.0
|
||||||
prefer_dark: bool = False
|
prefer_dark: bool = False
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -30,27 +31,38 @@ class Stats:
|
|||||||
"""Returns inverted brightness when prefer_dark is on."""
|
"""Returns inverted brightness when prefer_dark is on."""
|
||||||
return (100.0 - self.brightness_score) if self.prefer_dark else self.brightness_score
|
return (100.0 - self.brightness_score) if self.prefer_dark else self.brightness_score
|
||||||
|
|
||||||
@property
|
def composite_score(self, weights: dict[str, int]) -> float:
|
||||||
def composite_score(self) -> float:
|
"""Calculates weighted composite based on provided weights (0-100)."""
|
||||||
"""Weighted composite: 35% match_all + 55% match_keep + 10% brightness."""
|
|
||||||
pct_all = (self.matches_all / self.total_all * 100) if self.total_all else 0.0
|
pct_all = (self.matches_all / self.total_all * 100) if self.total_all else 0.0
|
||||||
pct_keep = (self.matches_keep / self.total_keep * 100) if self.total_keep else 0.0
|
pct_keep = (self.matches_keep / self.total_keep * 100) if self.total_keep else 0.0
|
||||||
return 0.35 * pct_all + 0.55 * pct_keep + 0.10 * self.effective_brightness
|
|
||||||
|
|
||||||
def summary(self, translate) -> str:
|
# weights keys: match_all, match_keep, brightness, grouping
|
||||||
|
w_all = weights.get("match_all", 30) / 100.0
|
||||||
|
w_keep = weights.get("match_keep", 50) / 100.0
|
||||||
|
w_bright = weights.get("brightness", 10) / 100.0
|
||||||
|
w_group = weights.get("grouping", 10) / 100.0
|
||||||
|
|
||||||
|
return (w_all * pct_all +
|
||||||
|
w_keep * pct_keep +
|
||||||
|
w_bright * self.effective_brightness +
|
||||||
|
w_group * self.grouping_score)
|
||||||
|
|
||||||
|
def summary(self, translate, weights: dict[str, int]) -> str:
|
||||||
if self.total_all == 0:
|
if self.total_all == 0:
|
||||||
return translate("stats.placeholder")
|
return translate("stats.placeholder")
|
||||||
with_pct = (self.matches_keep / self.total_keep * 100) if self.total_keep else 0.0
|
with_pct = (self.matches_keep / self.total_keep * 100) if self.total_keep else 0.0
|
||||||
without_pct = (self.matches_all / self.total_all * 100) if self.total_all else 0.0
|
without_pct = (self.matches_all / self.total_all * 100) if self.total_all else 0.0
|
||||||
excluded_pct = (self.total_excl / self.total_all * 100) if self.total_all else 0.0
|
excluded_pct = (self.total_excl / self.total_all * 100) if self.total_all else 0.0
|
||||||
brightness_label = translate("stats.darkness_label") if self.prefer_dark else translate("stats.brightness_label")
|
brightness_label = translate("stats.darkness_label") if self.prefer_dark else translate("stats.brightness_label")
|
||||||
|
score = self.composite_score(weights)
|
||||||
return translate(
|
return translate(
|
||||||
"stats.summary",
|
"stats.summary",
|
||||||
score=self.composite_score,
|
score=score,
|
||||||
with_pct=with_pct,
|
with_pct=with_pct,
|
||||||
without_pct=without_pct,
|
without_pct=without_pct,
|
||||||
brightness_label=brightness_label,
|
brightness_label=brightness_label,
|
||||||
brightness=self.effective_brightness,
|
brightness=self.effective_brightness,
|
||||||
|
grouping=self.grouping_score,
|
||||||
excluded_pct=excluded_pct,
|
excluded_pct=excluded_pct,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -106,6 +118,7 @@ class QtImageProcessor:
|
|||||||
"hue_min": 0,
|
"hue_min": 0,
|
||||||
"hue_max": 360,
|
"hue_max": 360,
|
||||||
"sat_min": 25,
|
"sat_min": 25,
|
||||||
|
"sat_max": 100,
|
||||||
"val_min": 15,
|
"val_min": 15,
|
||||||
"val_max": 100,
|
"val_max": 100,
|
||||||
"alpha": 120,
|
"alpha": 120,
|
||||||
@@ -113,6 +126,7 @@ class QtImageProcessor:
|
|||||||
self.hue_min = self.defaults["hue_min"]
|
self.hue_min = self.defaults["hue_min"]
|
||||||
self.hue_max = self.defaults["hue_max"]
|
self.hue_max = self.defaults["hue_max"]
|
||||||
self.sat_min = self.defaults["sat_min"]
|
self.sat_min = self.defaults["sat_min"]
|
||||||
|
self.sat_max = self.defaults["sat_max"]
|
||||||
self.val_min = self.defaults["val_min"]
|
self.val_min = self.defaults["val_min"]
|
||||||
self.val_max = self.defaults["val_max"]
|
self.val_max = self.defaults["val_max"]
|
||||||
self.alpha = self.defaults["alpha"]
|
self.alpha = self.defaults["alpha"]
|
||||||
@@ -125,6 +139,15 @@ class QtImageProcessor:
|
|||||||
self._cached_mask_size: Tuple[int, int] | None = None
|
self._cached_mask_size: Tuple[int, int] | None = None
|
||||||
self.exclude_ref_size: Tuple[int, int] | None = None
|
self.exclude_ref_size: Tuple[int, int] | None = None
|
||||||
self.prefer_dark: bool = False
|
self.prefer_dark: bool = False
|
||||||
|
self.exclude_bg: bool = True
|
||||||
|
self.exclude_bg_rgb: Tuple[int, int, int] = (31, 41, 55)
|
||||||
|
self.exclude_bg_tolerance: int = 5
|
||||||
|
self.weights: Dict[str, int] = {
|
||||||
|
"match_all": 30,
|
||||||
|
"match_keep": 50,
|
||||||
|
"brightness": 10,
|
||||||
|
"grouping": 10
|
||||||
|
}
|
||||||
|
|
||||||
def set_defaults(self, defaults: dict) -> None:
|
def set_defaults(self, defaults: dict) -> None:
|
||||||
for key in self.defaults:
|
for key in self.defaults:
|
||||||
@@ -182,13 +205,29 @@ class QtImageProcessor:
|
|||||||
if self.orig_img is None:
|
if self.orig_img is None:
|
||||||
self.preview_img = None
|
self.preview_img = None
|
||||||
return
|
return
|
||||||
width, height = self.orig_img.size
|
|
||||||
|
img_to_process = self.orig_img.convert("RGBA")
|
||||||
|
if self.exclude_bg:
|
||||||
|
# Mask the background color with tolerance on the original image before resizing
|
||||||
|
# this prevents interpolation artifacts from leaving a background 'halo'
|
||||||
|
arr = np.array(img_to_process)
|
||||||
|
r_bg, g_bg, b_bg = self.exclude_bg_rgb
|
||||||
|
tol = self.exclude_bg_tolerance
|
||||||
|
bg_mask = (
|
||||||
|
(np.abs(arr[..., 0].astype(np.int16) - r_bg) <= tol) &
|
||||||
|
(np.abs(arr[..., 1].astype(np.int16) - g_bg) <= tol) &
|
||||||
|
(np.abs(arr[..., 2].astype(np.int16) - b_bg) <= tol)
|
||||||
|
)
|
||||||
|
arr[bg_mask, 3] = 0
|
||||||
|
img_to_process = Image.fromarray(arr, "RGBA")
|
||||||
|
|
||||||
|
width, height = img_to_process.size
|
||||||
max_w, max_h = PREVIEW_MAX_SIZE
|
max_w, max_h = PREVIEW_MAX_SIZE
|
||||||
scale = min(max_w / width, max_h / height)
|
scale = min(max_w / width, max_h / height)
|
||||||
if scale <= 0:
|
if scale <= 0:
|
||||||
scale = 1.0
|
scale = 1.0
|
||||||
size = (max(1, int(width * scale)), max(1, int(height * scale)))
|
size = (max(1, int(width * scale)), max(1, int(height * scale)))
|
||||||
self.preview_img = self.orig_img.resize(size, Image.LANCZOS)
|
self.preview_img = img_to_process.resize(size, Image.LANCZOS)
|
||||||
|
|
||||||
def _rebuild_overlay(self) -> None:
|
def _rebuild_overlay(self) -> None:
|
||||||
"""Build color-match overlay using vectorized NumPy operations."""
|
"""Build color-match overlay using vectorized NumPy operations."""
|
||||||
@@ -201,7 +240,18 @@ class QtImageProcessor:
|
|||||||
arr = np.asarray(base, dtype=np.float32) # (H, W, 4)
|
arr = np.asarray(base, dtype=np.float32) # (H, W, 4)
|
||||||
|
|
||||||
rgb = arr[..., :3] / 255.0
|
rgb = arr[..., :3] / 255.0
|
||||||
alpha_ch = arr[..., 3] # alpha channel of the image
|
alpha_ch = arr[..., 3].copy() # alpha channel of the image
|
||||||
|
|
||||||
|
if self.exclude_bg:
|
||||||
|
# Exclude specific background color
|
||||||
|
r_bg, g_bg, b_bg = self.exclude_bg_rgb
|
||||||
|
tol = self.exclude_bg_tolerance
|
||||||
|
bg_mask = (
|
||||||
|
(np.abs(arr[..., 0] - r_bg) <= tol) &
|
||||||
|
(np.abs(arr[..., 1] - g_bg) <= tol) &
|
||||||
|
(np.abs(arr[..., 2] - b_bg) <= tol)
|
||||||
|
)
|
||||||
|
alpha_ch[bg_mask] = 0
|
||||||
|
|
||||||
hsv = _rgb_to_hsv_numpy(rgb) # (H, W, 3): H°, S%, V%
|
hsv = _rgb_to_hsv_numpy(rgb) # (H, W, 3): H°, S%, V%
|
||||||
|
|
||||||
@@ -219,9 +269,10 @@ class QtImageProcessor:
|
|||||||
match_mask = (
|
match_mask = (
|
||||||
hue_ok
|
hue_ok
|
||||||
& (sat >= float(self.sat_min))
|
& (sat >= float(self.sat_min))
|
||||||
|
& (sat <= float(self.sat_max))
|
||||||
& (val >= float(self.val_min))
|
& (val >= float(self.val_min))
|
||||||
& (val <= float(self.val_max))
|
& (val <= float(self.val_max))
|
||||||
& (alpha_ch > 0)
|
& (alpha_ch >= 128)
|
||||||
)
|
)
|
||||||
|
|
||||||
# Exclusion mask (same pixel space as preview)
|
# Exclusion mask (same pixel space as preview)
|
||||||
@@ -229,8 +280,7 @@ class QtImageProcessor:
|
|||||||
|
|
||||||
keep_match = match_mask & ~excl_mask
|
keep_match = match_mask & ~excl_mask
|
||||||
excl_match = match_mask & excl_mask
|
excl_match = match_mask & excl_mask
|
||||||
visible = alpha_ch > 0
|
visible = alpha_ch >= 128
|
||||||
|
|
||||||
matches_all = int(match_mask[visible].sum())
|
matches_all = int(match_mask[visible].sum())
|
||||||
total_all = int(visible.sum())
|
total_all = int(visible.sum())
|
||||||
matches_keep = int(keep_match[visible].sum())
|
matches_keep = int(keep_match[visible].sum())
|
||||||
@@ -242,6 +292,9 @@ class QtImageProcessor:
|
|||||||
keep_visible = visible & ~excl_mask
|
keep_visible = visible & ~excl_mask
|
||||||
brightness = float(val[keep_visible].mean()) if keep_visible.any() else 0.0
|
brightness = float(val[keep_visible].mean()) if keep_visible.any() else 0.0
|
||||||
|
|
||||||
|
# Grouping: measure clustering of match_mask
|
||||||
|
grouping = self._calculate_grouping_score(keep_match)
|
||||||
|
|
||||||
# Build overlay image
|
# Build overlay image
|
||||||
overlay_arr = np.zeros((base.height, base.width, 4), dtype=np.uint8)
|
overlay_arr = np.zeros((base.height, base.width, 4), dtype=np.uint8)
|
||||||
overlay_arr[keep_match, 0] = self.overlay_r
|
overlay_arr[keep_match, 0] = self.overlay_r
|
||||||
@@ -258,6 +311,7 @@ class QtImageProcessor:
|
|||||||
matches_excl=matches_excl,
|
matches_excl=matches_excl,
|
||||||
total_excl=total_excl,
|
total_excl=total_excl,
|
||||||
brightness_score=brightness,
|
brightness_score=brightness,
|
||||||
|
grouping_score=grouping,
|
||||||
prefer_dark=self.prefer_dark,
|
prefer_dark=self.prefer_dark,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -267,7 +321,18 @@ class QtImageProcessor:
|
|||||||
arr = np.asarray(base, dtype=np.float32)
|
arr = np.asarray(base, dtype=np.float32)
|
||||||
|
|
||||||
rgb = arr[..., :3] / 255.0
|
rgb = arr[..., :3] / 255.0
|
||||||
alpha_ch = arr[..., 3]
|
alpha_ch = arr[..., 3].copy()
|
||||||
|
|
||||||
|
if self.exclude_bg:
|
||||||
|
# Exclude background color with tolerance
|
||||||
|
r_bg, g_bg, b_bg = self.exclude_bg_rgb
|
||||||
|
tol = self.exclude_bg_tolerance
|
||||||
|
bg_mask = (
|
||||||
|
(np.abs(arr[..., 0] - r_bg) <= tol) &
|
||||||
|
(np.abs(arr[..., 1] - g_bg) <= tol) &
|
||||||
|
(np.abs(arr[..., 2] - b_bg) <= tol)
|
||||||
|
)
|
||||||
|
alpha_ch[bg_mask] = 0
|
||||||
|
|
||||||
hsv = _rgb_to_hsv_numpy(rgb)
|
hsv = _rgb_to_hsv_numpy(rgb)
|
||||||
|
|
||||||
@@ -285,20 +350,22 @@ class QtImageProcessor:
|
|||||||
match_mask = (
|
match_mask = (
|
||||||
hue_ok
|
hue_ok
|
||||||
& (sat >= float(self.sat_min))
|
& (sat >= float(self.sat_min))
|
||||||
|
& (sat <= float(self.sat_max))
|
||||||
& (val >= float(self.val_min))
|
& (val >= float(self.val_min))
|
||||||
& (val <= float(self.val_max))
|
& (val <= float(self.val_max))
|
||||||
& (alpha_ch > 0)
|
& (alpha_ch >= 128)
|
||||||
)
|
)
|
||||||
|
|
||||||
excl_mask = self._build_exclusion_mask_numpy(base.size)
|
excl_mask = self._build_exclusion_mask_numpy(base.size)
|
||||||
|
|
||||||
keep_match = match_mask & ~excl_mask
|
keep_match = match_mask & ~excl_mask
|
||||||
excl_match = match_mask & excl_mask
|
excl_match = match_mask & excl_mask
|
||||||
visible = alpha_ch > 0
|
|
||||||
|
|
||||||
|
visible = alpha_ch >= 128
|
||||||
matches_keep_count = int(keep_match[visible].sum())
|
matches_keep_count = int(keep_match[visible].sum())
|
||||||
keep_visible = visible & ~excl_mask
|
keep_visible = visible & ~excl_mask
|
||||||
brightness = float(val[keep_visible].mean()) if keep_visible.any() else 0.0
|
brightness = float(val[keep_visible].mean()) if keep_visible.any() else 0.0
|
||||||
|
grouping = self._calculate_grouping_score(keep_match)
|
||||||
|
|
||||||
return Stats(
|
return Stats(
|
||||||
matches_all=int(match_mask[visible].sum()),
|
matches_all=int(match_mask[visible].sum()),
|
||||||
@@ -308,9 +375,35 @@ class QtImageProcessor:
|
|||||||
matches_excl=int(excl_match[visible].sum()),
|
matches_excl=int(excl_match[visible].sum()),
|
||||||
total_excl=int((visible & excl_mask).sum()),
|
total_excl=int((visible & excl_mask).sum()),
|
||||||
brightness_score=brightness,
|
brightness_score=brightness,
|
||||||
|
grouping_score=grouping,
|
||||||
prefer_dark=self.prefer_dark,
|
prefer_dark=self.prefer_dark,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def _calculate_grouping_score(self, mask: np.ndarray) -> float:
|
||||||
|
"""Measure clustering: average density in a 9x9 neighborhood (0-100)."""
|
||||||
|
if not mask.any():
|
||||||
|
return 0.0
|
||||||
|
|
||||||
|
h, w = mask.shape
|
||||||
|
# Use cumulative sums for O(1) box sum calculation
|
||||||
|
padded = np.pad(mask, 5, mode='constant', constant_values=0)
|
||||||
|
cumsum = padded.astype(np.int32).cumsum(axis=0).cumsum(axis=1)
|
||||||
|
|
||||||
|
# Indices for 9x9 windows centered at each mask pixel
|
||||||
|
y2, x2 = np.arange(9, 9 + h)[:, None], np.arange(9, 9 + w)
|
||||||
|
y1_1, x1_1 = np.arange(0, h)[:, None], np.arange(0, w)
|
||||||
|
|
||||||
|
# Box sum formula: S(window) = S(x2,y2) - S(x1-1,y2) - S(x2,y1-1) + S(x1-1,y1-1)
|
||||||
|
window_sums = cumsum[y2, x2] - cumsum[y1_1, x2] - cumsum[y2, x1_1] + cumsum[y1_1, x1_1]
|
||||||
|
|
||||||
|
# Max neighbors in 9x9 is 80 (excluding the center pixel itself)
|
||||||
|
neighbors = (window_sums - mask.astype(np.int32)).clip(min=0)
|
||||||
|
|
||||||
|
match_neighbors = neighbors[mask]
|
||||||
|
# Square the density to heavily penalize thin bridges and frayed edges
|
||||||
|
score = ( (match_neighbors / 80.0) ** 2 ).mean() * 100.0
|
||||||
|
return float(score)
|
||||||
|
|
||||||
# helpers ----------------------------------------------------------------
|
# helpers ----------------------------------------------------------------
|
||||||
|
|
||||||
def _matches(self, r: int, g: int, b: int) -> bool:
|
def _matches(self, r: int, g: int, b: int) -> bool:
|
||||||
@@ -321,7 +414,7 @@ class QtImageProcessor:
|
|||||||
hue_ok = self.hue_min <= hue <= self.hue_max
|
hue_ok = self.hue_min <= hue <= self.hue_max
|
||||||
else:
|
else:
|
||||||
hue_ok = hue >= self.hue_min or hue <= self.hue_max
|
hue_ok = hue >= self.hue_min or hue <= self.hue_max
|
||||||
sat_ok = s * 100.0 >= self.sat_min
|
sat_ok = self.sat_min <= s * 100.0 <= self.sat_max
|
||||||
val_ok = self.val_min <= v * 100.0 <= self.val_max
|
val_ok = self.val_min <= v * 100.0 <= self.val_max
|
||||||
return hue_ok and sat_ok and val_ok
|
return hue_ok and sat_ok and val_ok
|
||||||
|
|
||||||
@@ -439,3 +532,21 @@ class QtImageProcessor:
|
|||||||
self._cached_mask = mask
|
self._cached_mask = mask
|
||||||
self._cached_mask_size = size
|
self._cached_mask_size = size
|
||||||
return mask
|
return mask
|
||||||
|
|
||||||
|
def set_exclude_bg_color(self, hex_code: str, tolerance: int = 5) -> None:
|
||||||
|
"""Set the RGB channels for background exclusion from a hex string."""
|
||||||
|
self.exclude_bg_tolerance = tolerance
|
||||||
|
if not hex_code.startswith("#") or len(hex_code) not in (7, 9):
|
||||||
|
return
|
||||||
|
try:
|
||||||
|
r = int(hex_code[1:3], 16)
|
||||||
|
g = int(hex_code[3:5], 16)
|
||||||
|
b = int(hex_code[5:7], 16)
|
||||||
|
self.exclude_bg_rgb = (r, g, b)
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
@property
|
||||||
|
def exclude_bg_color_hex(self) -> str:
|
||||||
|
r, g, b = self.exclude_bg_rgb
|
||||||
|
return f"#{r:02x}{g:02x}{b:02x}"
|
||||||
|
|||||||
+210
-30
@@ -41,6 +41,7 @@ SLIDER_SPECS: List[Tuple[str, str, int, int]] = [
|
|||||||
("sliders.hue_min", "hue_min", 0, 360),
|
("sliders.hue_min", "hue_min", 0, 360),
|
||||||
("sliders.hue_max", "hue_max", 0, 360),
|
("sliders.hue_max", "hue_max", 0, 360),
|
||||||
("sliders.sat_min", "sat_min", 0, 100),
|
("sliders.sat_min", "sat_min", 0, 100),
|
||||||
|
("sliders.sat_max", "sat_max", 0, 100),
|
||||||
("sliders.val_min", "val_min", 0, 100),
|
("sliders.val_min", "val_min", 0, 100),
|
||||||
("sliders.val_max", "val_max", 0, 100),
|
("sliders.val_max", "val_max", 0, 100),
|
||||||
("sliders.alpha", "alpha", 0, 255),
|
("sliders.alpha", "alpha", 0, 255),
|
||||||
@@ -512,10 +513,88 @@ class TitleBar(QtWidgets.QWidget):
|
|||||||
super().mousePressEvent(event)
|
super().mousePressEvent(event)
|
||||||
|
|
||||||
|
|
||||||
|
class WeightingDialog(QtWidgets.QDialog):
|
||||||
|
"""Dialog to customize weightings and preference before folder export."""
|
||||||
|
|
||||||
|
def __init__(self, parent: QtWidgets.QWidget, translate: Callable, current_weights: Dict[str, int], prefer_dark: bool):
|
||||||
|
super().__init__(parent)
|
||||||
|
self._t = translate
|
||||||
|
self.setWindowTitle(self._t("dialog.weighting_title"))
|
||||||
|
self.setFixedWidth(350)
|
||||||
|
|
||||||
|
layout = QtWidgets.QVBoxLayout(self)
|
||||||
|
layout.setSpacing(12)
|
||||||
|
|
||||||
|
instruction = QtWidgets.QLabel(self._t("dialog.weighting_instruction"))
|
||||||
|
instruction.setWordWrap(True)
|
||||||
|
layout.addWidget(instruction)
|
||||||
|
|
||||||
|
grid = QtWidgets.QGridLayout()
|
||||||
|
grid.setSpacing(10)
|
||||||
|
|
||||||
|
self.inputs: Dict[str, QtWidgets.QSpinBox] = {}
|
||||||
|
specs = [
|
||||||
|
("match_all", "dialog.weight_match_all"),
|
||||||
|
("match_keep", "dialog.weight_match_keep"),
|
||||||
|
("brightness", "dialog.weight_brightness"),
|
||||||
|
("grouping", "dialog.weight_grouping"),
|
||||||
|
]
|
||||||
|
|
||||||
|
for i, (key, label_key) in enumerate(specs):
|
||||||
|
label = QtWidgets.QLabel(self._t(label_key))
|
||||||
|
spin = QtWidgets.QSpinBox()
|
||||||
|
spin.setRange(0, 100)
|
||||||
|
spin.setSuffix("%")
|
||||||
|
spin.setValue(current_weights.get(key, 0))
|
||||||
|
spin.valueChanged.connect(self._update_total)
|
||||||
|
grid.addWidget(label, i, 0)
|
||||||
|
grid.addWidget(spin, i, 1)
|
||||||
|
self.inputs[key] = spin
|
||||||
|
|
||||||
|
layout.addLayout(grid)
|
||||||
|
|
||||||
|
self.total_label = QtWidgets.QLabel(f"{self._t('dialog.total_weight')} 100%")
|
||||||
|
self.total_label.setStyleSheet("font-weight: bold;")
|
||||||
|
layout.addWidget(self.total_label)
|
||||||
|
|
||||||
|
self.prefer_dark_cb = QtWidgets.QCheckBox(self._t("toolbar.prefer_dark"))
|
||||||
|
self.prefer_dark_cb.setChecked(prefer_dark)
|
||||||
|
layout.addWidget(self.prefer_dark_cb)
|
||||||
|
|
||||||
|
buttons = QtWidgets.QDialogButtonBox(QtWidgets.QDialogButtonBox.Ok | QtWidgets.QDialogButtonBox.Cancel)
|
||||||
|
buttons.accepted.connect(self._validate_and_accept)
|
||||||
|
buttons.rejected.connect(self.reject)
|
||||||
|
self.ok_button = buttons.button(QtWidgets.QDialogButtonBox.Ok)
|
||||||
|
layout.addWidget(buttons)
|
||||||
|
|
||||||
|
self._update_total()
|
||||||
|
|
||||||
|
def _update_total(self) -> None:
|
||||||
|
total = sum(s.value() for s in self.inputs.values())
|
||||||
|
self.total_label.setText(f"{self._t('dialog.total_weight')} {total}%")
|
||||||
|
if total == 100:
|
||||||
|
self.total_label.setStyleSheet("color: #34c759; font-weight: bold;")
|
||||||
|
self.ok_button.setEnabled(True)
|
||||||
|
else:
|
||||||
|
self.total_label.setStyleSheet("color: #ff3b30; font-weight: bold;")
|
||||||
|
self.ok_button.setEnabled(False)
|
||||||
|
|
||||||
|
def _validate_and_accept(self) -> None:
|
||||||
|
total = sum(s.value() for s in self.inputs.values())
|
||||||
|
if total != 100:
|
||||||
|
QtWidgets.QMessageBox.warning(self, self._t("dialog.error_title"), self._t("dialog.weight_error", total=total))
|
||||||
|
return
|
||||||
|
self.accept()
|
||||||
|
|
||||||
|
def get_values(self) -> Tuple[Dict[str, int], bool]:
|
||||||
|
weights = {k: s.value() for k, s in self.inputs.items()}
|
||||||
|
return weights, self.prefer_dark_cb.isChecked()
|
||||||
|
|
||||||
|
|
||||||
class MainWindow(QtWidgets.QMainWindow, I18nMixin):
|
class MainWindow(QtWidgets.QMainWindow, I18nMixin):
|
||||||
"""Main application window containing all controls."""
|
"""Main application window containing all controls."""
|
||||||
|
|
||||||
def __init__(self, language: str, defaults: dict, reset_exclusions: bool, overlay_color: str | None = None) -> None:
|
def __init__(self, language: str, defaults: dict, reset_exclusions: bool, overlay_color: str | None = None, exclude_bg_color: str | None = None, exclude_bg_tolerance: int = 5) -> None:
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.init_i18n(language)
|
self.init_i18n(language)
|
||||||
self.setWindowTitle(self._t("app.title"))
|
self.setWindowTitle(self._t("app.title"))
|
||||||
@@ -539,6 +618,8 @@ class MainWindow(QtWidgets.QMainWindow, I18nMixin):
|
|||||||
self.processor.reset_exclusions_on_switch = reset_exclusions
|
self.processor.reset_exclusions_on_switch = reset_exclusions
|
||||||
# Always use red for the overlay regardless of the target color
|
# Always use red for the overlay regardless of the target color
|
||||||
self.processor.set_overlay_color(DEFAULT_OVERLAY_HEX)
|
self.processor.set_overlay_color(DEFAULT_OVERLAY_HEX)
|
||||||
|
if exclude_bg_color:
|
||||||
|
self.processor.set_exclude_bg_color(exclude_bg_color, tolerance=exclude_bg_tolerance)
|
||||||
|
|
||||||
self.content_layout = QtWidgets.QVBoxLayout(self.content)
|
self.content_layout = QtWidgets.QVBoxLayout(self.content)
|
||||||
self.content_layout.setContentsMargins(24, 0, 24, 24)
|
self.content_layout.setContentsMargins(24, 0, 24, 24)
|
||||||
@@ -654,6 +735,13 @@ class MainWindow(QtWidgets.QMainWindow, I18nMixin):
|
|||||||
self.prefer_dark_action.setChecked(False)
|
self.prefer_dark_action.setChecked(False)
|
||||||
self.prefer_dark_action.triggered.connect(lambda: self._invoke_action("toggle_prefer_dark"))
|
self.prefer_dark_action.triggered.connect(lambda: self._invoke_action("toggle_prefer_dark"))
|
||||||
view_menu.addAction(self.prefer_dark_action)
|
view_menu.addAction(self.prefer_dark_action)
|
||||||
|
|
||||||
|
self.exclude_bg_action = QtGui.QAction("🖼 " + self._t("toolbar.exclude_bg", color=self.processor.exclude_bg_color_hex), self)
|
||||||
|
self.exclude_bg_action.setCheckable(True)
|
||||||
|
self.exclude_bg_action.setChecked(True)
|
||||||
|
self.exclude_bg_action.triggered.connect(lambda: self._invoke_action("toggle_exclude_bg"))
|
||||||
|
view_menu.addAction(self.exclude_bg_action)
|
||||||
|
|
||||||
view_menu.addSeparator()
|
view_menu.addSeparator()
|
||||||
view_menu.addAction("📁 " + self._t("toolbar.open_app_folder"), lambda: self._invoke_action("open_app_folder"))
|
view_menu.addAction("📁 " + self._t("toolbar.open_app_folder"), lambda: self._invoke_action("open_app_folder"))
|
||||||
|
|
||||||
@@ -688,7 +776,7 @@ class MainWindow(QtWidgets.QMainWindow, I18nMixin):
|
|||||||
swatch_container.setSpacing(8)
|
swatch_container.setSpacing(8)
|
||||||
self.swatch_buttons: List[ColorSwatch] = []
|
self.swatch_buttons: List[ColorSwatch] = []
|
||||||
for name_key, hex_code in PRESET_COLORS:
|
for name_key, hex_code in PRESET_COLORS:
|
||||||
swatch = ColorSwatch(self._t(name_key), hex_code, self._update_color_display)
|
swatch = ColorSwatch(self._t(name_key), hex_code, lambda h, l: self._update_color_display(h, l, update_range=True))
|
||||||
swatch_container.addWidget(swatch)
|
swatch_container.addWidget(swatch)
|
||||||
self.swatch_buttons.append(swatch)
|
self.swatch_buttons.append(swatch)
|
||||||
layout.addLayout(swatch_container)
|
layout.addLayout(swatch_container)
|
||||||
@@ -805,6 +893,7 @@ class MainWindow(QtWidgets.QMainWindow, I18nMixin):
|
|||||||
"reset_sliders": self._reset_sliders,
|
"reset_sliders": self._reset_sliders,
|
||||||
"toggle_theme": self.toggle_theme,
|
"toggle_theme": self.toggle_theme,
|
||||||
"toggle_prefer_dark": self.toggle_prefer_dark,
|
"toggle_prefer_dark": self.toggle_prefer_dark,
|
||||||
|
"toggle_exclude_bg": self.toggle_exclude_bg,
|
||||||
"open_app_folder": self.open_app_folder,
|
"open_app_folder": self.open_app_folder,
|
||||||
"show_previous_image": self.show_previous_image,
|
"show_previous_image": self.show_previous_image,
|
||||||
"show_next_image": self.show_next_image,
|
"show_next_image": self.show_next_image,
|
||||||
@@ -855,7 +944,7 @@ class MainWindow(QtWidgets.QMainWindow, I18nMixin):
|
|||||||
|
|
||||||
def open_image(self) -> None:
|
def open_image(self) -> None:
|
||||||
filters = "Images (*.png *.jpg *.jpeg *.bmp *.webp)"
|
filters = "Images (*.png *.jpg *.jpeg *.bmp *.webp)"
|
||||||
default_dir = str(Path("images").absolute()) if Path("images").exists() else ""
|
default_dir = str(Path("analyses").absolute()) if Path("analyses").exists() else ""
|
||||||
path_str, _ = QtWidgets.QFileDialog.getOpenFileName(self, self._t("dialog.open_image_title"), default_dir, filters)
|
path_str, _ = QtWidgets.QFileDialog.getOpenFileName(self, self._t("dialog.open_image_title"), default_dir, filters)
|
||||||
if not path_str:
|
if not path_str:
|
||||||
return
|
return
|
||||||
@@ -872,7 +961,7 @@ class MainWindow(QtWidgets.QMainWindow, I18nMixin):
|
|||||||
self._refresh_views()
|
self._refresh_views()
|
||||||
|
|
||||||
def open_folder(self) -> None:
|
def open_folder(self) -> None:
|
||||||
default_dir = str(Path("images").absolute()) if Path("images").exists() else ""
|
default_dir = str(Path("analyses").absolute()) if Path("analyses").exists() else ""
|
||||||
directory = QtWidgets.QFileDialog.getExistingDirectory(self, self._t("dialog.open_folder_title"), default_dir)
|
directory = QtWidgets.QFileDialog.getExistingDirectory(self, self._t("dialog.open_folder_title"), default_dir)
|
||||||
if not directory:
|
if not directory:
|
||||||
return
|
return
|
||||||
@@ -894,20 +983,28 @@ class MainWindow(QtWidgets.QMainWindow, I18nMixin):
|
|||||||
|
|
||||||
def export_settings(self) -> None:
|
def export_settings(self) -> None:
|
||||||
item_name = ""
|
item_name = ""
|
||||||
|
default_dir = Path("analyses").absolute() if Path("analyses").exists() else Path()
|
||||||
|
|
||||||
if self._current_image_path:
|
if self._current_image_path:
|
||||||
# Try to get folder name first, otherwise file name
|
if self._current_image_path.parent.name == "images":
|
||||||
if self._current_image_path.parent.name and self._current_image_path.parent.name != "images":
|
root_dir = self._current_image_path.parent.parent
|
||||||
item_name = self._current_image_path.parent.name
|
item_name = root_dir.name
|
||||||
|
default_dir = root_dir / "settings"
|
||||||
|
elif self._current_image_path.parent.name and self._current_image_path.parent.name != "images":
|
||||||
|
root_dir = self._current_image_path.parent
|
||||||
|
item_name = root_dir.name
|
||||||
|
default_dir = root_dir / "settings"
|
||||||
else:
|
else:
|
||||||
item_name = self._current_image_path.stem
|
item_name = self._current_image_path.stem
|
||||||
|
default_dir = self._current_image_path.parent / "settings"
|
||||||
|
|
||||||
|
default_dir.mkdir(parents=True, exist_ok=True)
|
||||||
default_filename = f"icra_settings_{item_name}.json" if item_name else "icra_settings.json"
|
default_filename = f"icra_settings_{item_name}.json" if item_name else "icra_settings.json"
|
||||||
|
|
||||||
default_dir = str(Path("images").absolute()) if Path("images").exists() else ""
|
|
||||||
path_str, _ = QtWidgets.QFileDialog.getSaveFileName(
|
path_str, _ = QtWidgets.QFileDialog.getSaveFileName(
|
||||||
self,
|
self,
|
||||||
self._t("dialog.export_settings_title"),
|
self._t("dialog.export_settings_title"),
|
||||||
str(Path(default_dir) / default_filename),
|
str(default_dir / default_filename),
|
||||||
self._t("dialog.json_filter")
|
self._t("dialog.json_filter")
|
||||||
)
|
)
|
||||||
if not path_str:
|
if not path_str:
|
||||||
@@ -917,9 +1014,12 @@ class MainWindow(QtWidgets.QMainWindow, I18nMixin):
|
|||||||
"hue_min": self.processor.hue_min,
|
"hue_min": self.processor.hue_min,
|
||||||
"hue_max": self.processor.hue_max,
|
"hue_max": self.processor.hue_max,
|
||||||
"sat_min": self.processor.sat_min,
|
"sat_min": self.processor.sat_min,
|
||||||
|
"sat_max": self.processor.sat_max,
|
||||||
"val_min": self.processor.val_min,
|
"val_min": self.processor.val_min,
|
||||||
"val_max": self.processor.val_max,
|
"val_max": self.processor.val_max,
|
||||||
"alpha": self.processor.alpha,
|
"alpha": self.processor.alpha,
|
||||||
|
"prefer_dark": self.processor.prefer_dark,
|
||||||
|
"weights": self.processor.weights,
|
||||||
"current_color": self._current_color,
|
"current_color": self._current_color,
|
||||||
"exclude_ref_size": self.processor.exclude_ref_size,
|
"exclude_ref_size": self.processor.exclude_ref_size,
|
||||||
"shapes": self.image_view.shapes
|
"shapes": self.image_view.shapes
|
||||||
@@ -933,11 +1033,25 @@ class MainWindow(QtWidgets.QMainWindow, I18nMixin):
|
|||||||
QtWidgets.QMessageBox.warning(self, self._t("dialog.error_title"), str(e))
|
QtWidgets.QMessageBox.warning(self, self._t("dialog.error_title"), str(e))
|
||||||
|
|
||||||
def import_settings(self) -> None:
|
def import_settings(self) -> None:
|
||||||
default_dir = str(Path("images").absolute()) if Path("images").exists() else ""
|
default_dir = Path("analyses").absolute() if Path("analyses").exists() else Path()
|
||||||
|
|
||||||
|
if self._current_image_path:
|
||||||
|
if self._current_image_path.parent.name == "images":
|
||||||
|
root_dir = self._current_image_path.parent.parent
|
||||||
|
default_dir = root_dir / "settings"
|
||||||
|
elif self._current_image_path.parent.name and self._current_image_path.parent.name != "images":
|
||||||
|
root_dir = self._current_image_path.parent
|
||||||
|
default_dir = root_dir / "settings"
|
||||||
|
else:
|
||||||
|
default_dir = self._current_image_path.parent / "settings"
|
||||||
|
|
||||||
|
if not default_dir.exists():
|
||||||
|
default_dir = Path("analyses").absolute() if Path("analyses").exists() else Path()
|
||||||
|
|
||||||
path_str, _ = QtWidgets.QFileDialog.getOpenFileName(
|
path_str, _ = QtWidgets.QFileDialog.getOpenFileName(
|
||||||
self,
|
self,
|
||||||
self._t("dialog.import_settings_title"),
|
self._t("dialog.import_settings_title"),
|
||||||
default_dir,
|
str(default_dir),
|
||||||
self._t("dialog.json_filter")
|
self._t("dialog.json_filter")
|
||||||
)
|
)
|
||||||
if not path_str:
|
if not path_str:
|
||||||
@@ -954,10 +1068,12 @@ class MainWindow(QtWidgets.QMainWindow, I18nMixin):
|
|||||||
self._update_color_display(self._current_color, self._t("palette.current"))
|
self._update_color_display(self._current_color, self._t("palette.current"))
|
||||||
|
|
||||||
# 2. Apply slider values
|
# 2. Apply slider values
|
||||||
keys = ["hue_min", "hue_max", "sat_min", "val_min", "val_max", "alpha"]
|
keys = ["hue_min", "hue_max", "sat_min", "sat_max", "val_min", "val_max", "alpha"]
|
||||||
for key in keys:
|
for key in keys:
|
||||||
if key in settings:
|
if key in settings:
|
||||||
setattr(self.processor, key, settings[key])
|
setattr(self.processor, key, settings[key])
|
||||||
|
else:
|
||||||
|
setattr(self.processor, key, self.processor.defaults.get(key, 0))
|
||||||
|
|
||||||
# 3. Apply shapes and reference size
|
# 3. Apply shapes and reference size
|
||||||
ref_size = None
|
ref_size = None
|
||||||
@@ -972,6 +1088,13 @@ class MainWindow(QtWidgets.QMainWindow, I18nMixin):
|
|||||||
if self.processor.preview_img:
|
if self.processor.preview_img:
|
||||||
self.processor._rebuild_overlay()
|
self.processor._rebuild_overlay()
|
||||||
|
|
||||||
|
if "prefer_dark" in settings:
|
||||||
|
self.processor.prefer_dark = bool(settings["prefer_dark"])
|
||||||
|
self.prefer_dark_action.setChecked(self.processor.prefer_dark)
|
||||||
|
|
||||||
|
if "weights" in settings:
|
||||||
|
self.processor.weights = settings["weights"]
|
||||||
|
|
||||||
self._sync_sliders_from_processor()
|
self._sync_sliders_from_processor()
|
||||||
self._refresh_views()
|
self._refresh_views()
|
||||||
self.status_label.setText(self._t("status.settings_imported"))
|
self.status_label.setText(self._t("status.settings_imported"))
|
||||||
@@ -985,24 +1108,46 @@ class MainWindow(QtWidgets.QMainWindow, I18nMixin):
|
|||||||
return
|
return
|
||||||
|
|
||||||
folder_path = self.processor.preview_paths[0].parent
|
folder_path = self.processor.preview_paths[0].parent
|
||||||
default_filename = f"icra_stats_{folder_path.name}.csv"
|
|
||||||
|
if folder_path.name == "images":
|
||||||
|
root_dir = folder_path.parent
|
||||||
|
item_name = root_dir.name
|
||||||
|
else:
|
||||||
|
root_dir = folder_path
|
||||||
|
item_name = root_dir.name
|
||||||
|
|
||||||
|
target_dir = root_dir / "results"
|
||||||
|
target_dir.mkdir(parents=True, exist_ok=True)
|
||||||
|
default_filename = f"icra_results_{item_name}.csv" if item_name else "icra_results.csv"
|
||||||
|
|
||||||
csv_path, _ = QtWidgets.QFileDialog.getSaveFileName(
|
csv_path, _ = QtWidgets.QFileDialog.getSaveFileName(
|
||||||
self,
|
self,
|
||||||
self._t("dialog.export_stats_title"),
|
self._t("dialog.export_stats_title"),
|
||||||
str(folder_path / default_filename),
|
str(target_dir / default_filename),
|
||||||
self._t("dialog.csv_filter")
|
self._t("dialog.csv_filter")
|
||||||
)
|
)
|
||||||
if not csv_path:
|
if not csv_path:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# Show weighting dialog
|
||||||
|
diag = WeightingDialog(self, self._t, self.processor.weights, self.processor.prefer_dark)
|
||||||
|
if diag.exec() != QtWidgets.QDialog.Accepted:
|
||||||
|
return
|
||||||
|
|
||||||
|
new_weights, new_prefer_dark = diag.get_values()
|
||||||
|
self.processor.weights = new_weights
|
||||||
|
self.processor.prefer_dark = new_prefer_dark
|
||||||
|
# Update UI state
|
||||||
|
self.prefer_dark_action.setChecked(new_prefer_dark)
|
||||||
|
self._refresh_overlay_only()
|
||||||
|
|
||||||
total = len(self.processor.preview_paths)
|
total = len(self.processor.preview_paths)
|
||||||
|
|
||||||
# Hardcoded to EU format as requested: ; delimiter, , decimal
|
# Hardcoded to EU format as requested: ; delimiter, , decimal
|
||||||
delimiter = ";"
|
delimiter = ";"
|
||||||
decimal = ","
|
decimal = ","
|
||||||
|
|
||||||
brightness_col = "Darkness Score" if self.processor.prefer_dark else "Brightness Score"
|
brightness_col = self._t("stats.darkness_label") if self.processor.prefer_dark else self._t("stats.brightness_label")
|
||||||
headers = [
|
headers = [
|
||||||
"Filename",
|
"Filename",
|
||||||
"Color",
|
"Color",
|
||||||
@@ -1010,6 +1155,7 @@ class MainWindow(QtWidgets.QMainWindow, I18nMixin):
|
|||||||
"Matching Pixels w/ Exclusions",
|
"Matching Pixels w/ Exclusions",
|
||||||
"Excluded Pixels",
|
"Excluded Pixels",
|
||||||
brightness_col,
|
brightness_col,
|
||||||
|
self._t("stats.grouping_label"),
|
||||||
"Composite Score"
|
"Composite Score"
|
||||||
]
|
]
|
||||||
rows = [headers]
|
rows = [headers]
|
||||||
@@ -1027,7 +1173,8 @@ class MainWindow(QtWidgets.QMainWindow, I18nMixin):
|
|||||||
pct_keep_str = f"{pct_keep:.2f}".replace(".", decimal)
|
pct_keep_str = f"{pct_keep:.2f}".replace(".", decimal)
|
||||||
pct_excl_str = f"{pct_excl:.2f}".replace(".", decimal)
|
pct_excl_str = f"{pct_excl:.2f}".replace(".", decimal)
|
||||||
brightness_str = f"{s.effective_brightness:.2f}".replace(".", decimal)
|
brightness_str = f"{s.effective_brightness:.2f}".replace(".", decimal)
|
||||||
composite_str = f"{s.composite_score:.2f}".replace(".", decimal)
|
grouping_str = f"{s.grouping_score:.2f}".replace(".", decimal)
|
||||||
|
composite_str = f"{s.composite_score(self.processor.weights):.2f}".replace(".", decimal)
|
||||||
|
|
||||||
img.close()
|
img.close()
|
||||||
return [
|
return [
|
||||||
@@ -1037,10 +1184,11 @@ class MainWindow(QtWidgets.QMainWindow, I18nMixin):
|
|||||||
pct_keep_str,
|
pct_keep_str,
|
||||||
pct_excl_str,
|
pct_excl_str,
|
||||||
brightness_str,
|
brightness_str,
|
||||||
|
grouping_str,
|
||||||
composite_str
|
composite_str
|
||||||
]
|
]
|
||||||
except Exception:
|
except Exception:
|
||||||
return [img_path.name, self._current_color, "Error", "Error", "Error", "Error", "Error"]
|
return [img_path.name, self._current_color, "Error", "Error", "Error", "Error", "Error", "Error"]
|
||||||
|
|
||||||
results = [None] * total
|
results = [None] * total
|
||||||
with concurrent.futures.ThreadPoolExecutor() as executor:
|
with concurrent.futures.ThreadPoolExecutor() as executor:
|
||||||
@@ -1099,14 +1247,42 @@ class MainWindow(QtWidgets.QMainWindow, I18nMixin):
|
|||||||
|
|
||||||
# Helpers ----------------------------------------------------------------
|
# Helpers ----------------------------------------------------------------
|
||||||
|
|
||||||
def _update_color_display(self, hex_code: str, label: str) -> None:
|
def _update_color_display(self, hex_code: str, label: str, update_range: bool = False) -> None:
|
||||||
self._current_color = hex_code
|
self._current_color = hex_code
|
||||||
self.current_color_swatch.setStyleSheet(f"background-color: {hex_code}; border-radius: 6px;")
|
self.current_color_swatch.setStyleSheet(f"background-color: {hex_code}; border-radius: 6px;")
|
||||||
self.current_color_label.setText(f"({hex_code})")
|
self.current_color_label.setText(f"({hex_code})")
|
||||||
# Do NOT call self.processor.set_overlay_color here to keep overlay RED
|
|
||||||
if label:
|
if label:
|
||||||
self.status_label.setText(f"{label}: {hex_code}")
|
self.status_label.setText(f"{label}: {hex_code}")
|
||||||
|
|
||||||
|
if update_range:
|
||||||
|
# Convert hex to HSV and update sliders/thresholds
|
||||||
|
qcolor = QtGui.QColor(hex_code)
|
||||||
|
h, s, v, _ = qcolor.getHsv()
|
||||||
|
# QColor H is 0-359 or -1 for grayscale, S/V/A are 0-255
|
||||||
|
hue = h if h >= 0 else 0
|
||||||
|
sat_pct = (s / 255.0) * 100.0
|
||||||
|
val_pct = (v / 255.0) * 100.0
|
||||||
|
|
||||||
|
margin = 15
|
||||||
|
hue_min = max(0, int(hue) - margin)
|
||||||
|
hue_max = min(360, int(hue) + margin)
|
||||||
|
sat_min = max(0, int(sat_pct) - 20)
|
||||||
|
sat_max = min(100, int(sat_pct) + 20)
|
||||||
|
val_min = max(0, int(val_pct) - 30)
|
||||||
|
val_max = 100
|
||||||
|
|
||||||
|
for attr, val_score in [
|
||||||
|
("hue_min", hue_min), ("hue_max", hue_max),
|
||||||
|
("sat_min", sat_min), ("sat_max", sat_max),
|
||||||
|
("val_min", val_min), ("val_max", val_max),
|
||||||
|
]:
|
||||||
|
ctrl = self._slider_controls.get(attr)
|
||||||
|
if ctrl:
|
||||||
|
# set_value on SliderControl blocks signals, so we set processor manually
|
||||||
|
ctrl.set_value(val_score)
|
||||||
|
self.processor.set_threshold(attr, val_score)
|
||||||
|
self._refresh_overlay_only()
|
||||||
|
|
||||||
def _on_slider_change(self, key: str, value: int) -> None:
|
def _on_slider_change(self, key: str, value: int) -> None:
|
||||||
self.processor.set_threshold(key, value)
|
self.processor.set_threshold(key, value)
|
||||||
label = self._slider_title(key)
|
label = self._slider_title(key)
|
||||||
@@ -1123,13 +1299,6 @@ class MainWindow(QtWidgets.QMainWindow, I18nMixin):
|
|||||||
self.status_label.setText(self._t("status.defaults_restored"))
|
self.status_label.setText(self._t("status.defaults_restored"))
|
||||||
self._refresh_overlay_only()
|
self._refresh_overlay_only()
|
||||||
|
|
||||||
def _coming_soon(self) -> None:
|
|
||||||
QtWidgets.QMessageBox.information(
|
|
||||||
self,
|
|
||||||
self._t("dialog.info_title"),
|
|
||||||
"Feature coming soon in the PySide6 migration.",
|
|
||||||
)
|
|
||||||
|
|
||||||
# Shortcuts --------------------------------------------------------------
|
# Shortcuts --------------------------------------------------------------
|
||||||
|
|
||||||
def _setup_shortcuts(self) -> None:
|
def _setup_shortcuts(self) -> None:
|
||||||
@@ -1177,13 +1346,15 @@ class MainWindow(QtWidgets.QMainWindow, I18nMixin):
|
|||||||
margin = 15
|
margin = 15
|
||||||
hue_min = max(0, int(hue) - margin)
|
hue_min = max(0, int(hue) - margin)
|
||||||
hue_max = min(360, int(hue) + margin)
|
hue_max = min(360, int(hue) + margin)
|
||||||
|
# For a picked color, give a window of ±20% for saturation and -30% for value
|
||||||
sat_min = max(0, int(sat) - 20)
|
sat_min = max(0, int(sat) - 20)
|
||||||
|
sat_max = min(100, int(sat) + 20)
|
||||||
val_min = max(0, int(val) - 30)
|
val_min = max(0, int(val) - 30)
|
||||||
val_max = 100
|
val_max = 100
|
||||||
|
|
||||||
for attr, value in [
|
for attr, value in [
|
||||||
("hue_min", hue_min), ("hue_max", hue_max),
|
("hue_min", hue_min), ("hue_max", hue_max),
|
||||||
("sat_min", sat_min), ("val_min", val_min), ("val_max", val_max),
|
("sat_min", sat_min), ("sat_max", sat_max), ("val_min", val_min), ("val_max", val_max),
|
||||||
]:
|
]:
|
||||||
ctrl = self._slider_controls.get(attr)
|
ctrl = self._slider_controls.get(attr)
|
||||||
if ctrl:
|
if ctrl:
|
||||||
@@ -1259,7 +1430,7 @@ class MainWindow(QtWidgets.QMainWindow, I18nMixin):
|
|||||||
if not color.isValid():
|
if not color.isValid():
|
||||||
return
|
return
|
||||||
hex_code = color.name()
|
hex_code = color.name()
|
||||||
self._update_color_display(hex_code, self._t("dialog.choose_color_title"))
|
self._update_color_display(hex_code, self._t("dialog.choose_color_title"), update_range=True)
|
||||||
|
|
||||||
def save_overlay(self) -> None:
|
def save_overlay(self) -> None:
|
||||||
pixmap = self.processor.overlay_pixmap()
|
pixmap = self.processor.overlay_pixmap()
|
||||||
@@ -1293,6 +1464,15 @@ class MainWindow(QtWidgets.QMainWindow, I18nMixin):
|
|||||||
self.processor._rebuild_overlay()
|
self.processor._rebuild_overlay()
|
||||||
self._refresh_overlay_only()
|
self._refresh_overlay_only()
|
||||||
|
|
||||||
|
def toggle_exclude_bg(self) -> None:
|
||||||
|
self.processor.exclude_bg = not self.processor.exclude_bg
|
||||||
|
self.exclude_bg_action.setChecked(self.processor.exclude_bg)
|
||||||
|
if self._current_image_path:
|
||||||
|
# Re-scale/re-apply transparency
|
||||||
|
self.processor._build_preview()
|
||||||
|
self.processor._rebuild_overlay()
|
||||||
|
self._refresh_views()
|
||||||
|
|
||||||
def clear_exclusions(self) -> None:
|
def clear_exclusions(self) -> None:
|
||||||
self.image_view.clear_shapes()
|
self.image_view.clear_shapes()
|
||||||
self.processor.set_exclusions([])
|
self.processor.set_exclusions([])
|
||||||
@@ -1445,7 +1625,7 @@ class MainWindow(QtWidgets.QMainWindow, I18nMixin):
|
|||||||
# Update prefix translation correctly
|
# Update prefix translation correctly
|
||||||
prefix = self._t("status.loaded", name="X", dimensions="Y", position="Z").split("X")[0]
|
prefix = self._t("status.loaded", name="X", dimensions="Y", position="Z").split("X")[0]
|
||||||
self.filename_prefix_label.setText(prefix)
|
self.filename_prefix_label.setText(prefix)
|
||||||
self.ratio_label.setText(self.processor.stats.summary(self._t))
|
self.ratio_label.setText(self.processor.stats.summary(self._t, self.processor.weights))
|
||||||
|
|
||||||
def _refresh_overlay_only(self) -> None:
|
def _refresh_overlay_only(self) -> None:
|
||||||
if self.processor.preview_img is None:
|
if self.processor.preview_img is None:
|
||||||
@@ -1455,7 +1635,7 @@ class MainWindow(QtWidgets.QMainWindow, I18nMixin):
|
|||||||
self.overlay_view.clear_canvas()
|
self.overlay_view.clear_canvas()
|
||||||
else:
|
else:
|
||||||
self.overlay_view.set_pixmap(self._overlay_with_outlines(pix))
|
self.overlay_view.set_pixmap(self._overlay_with_outlines(pix))
|
||||||
self.ratio_label.setText(self.processor.stats.summary(self._t))
|
self.ratio_label.setText(self.processor.stats.summary(self._t, self.processor.weights))
|
||||||
|
|
||||||
def _on_shapes_changed(self, shapes: list[dict[str, object]]) -> None:
|
def _on_shapes_changed(self, shapes: list[dict[str, object]]) -> None:
|
||||||
self.processor.set_exclusions(shapes)
|
self.processor.set_exclusions(shapes)
|
||||||
|
|||||||
@@ -30,17 +30,32 @@ class PatternDownloadWorker(QtCore.QThread):
|
|||||||
filename = self.save_dir / f"{seed}.png"
|
filename = self.save_dir / f"{seed}.png"
|
||||||
|
|
||||||
if filename.exists():
|
if filename.exists():
|
||||||
|
try:
|
||||||
|
from PIL import Image
|
||||||
|
with Image.open(filename) as img:
|
||||||
|
img.verify()
|
||||||
return True, None
|
return True, None
|
||||||
|
except Exception:
|
||||||
|
filename.unlink(missing_ok=True)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
req = urllib.request.Request(url, headers={'User-Agent': 'Mozilla/5.0 ICRA/1.0'})
|
req = urllib.request.Request(url, headers={'User-Agent': 'Mozilla/5.0 ICRA/1.0'})
|
||||||
with urllib.request.urlopen(req, timeout=10) as response:
|
with urllib.request.urlopen(req, timeout=10) as response:
|
||||||
with open(filename, 'wb') as f:
|
with open(filename, 'wb') as f:
|
||||||
f.write(response.read())
|
f.write(response.read())
|
||||||
|
|
||||||
|
try:
|
||||||
|
from PIL import Image
|
||||||
|
with Image.open(filename) as img:
|
||||||
|
img.verify()
|
||||||
return True, None
|
return True, None
|
||||||
|
except Exception:
|
||||||
|
filename.unlink(missing_ok=True)
|
||||||
|
return False, "Downloaded file is invalid/corrupt"
|
||||||
except urllib.error.HTTPError as e:
|
except urllib.error.HTTPError as e:
|
||||||
return False, f"HTTP {e.code}"
|
return False, f"HTTP {e.code}"
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
filename.unlink(missing_ok=True)
|
||||||
return False, f"Network error: {e}"
|
return False, f"Network error: {e}"
|
||||||
|
|
||||||
def run(self) -> None:
|
def run(self) -> None:
|
||||||
@@ -140,7 +155,7 @@ class PatternPullerDialog(QtWidgets.QDialog, I18nMixin):
|
|||||||
QtWidgets.QMessageBox.warning(self, "Error", self._t("dialog.puller_invalid_url", default="Invalid URL format."))
|
QtWidgets.QMessageBox.warning(self, "Error", self._t("dialog.puller_invalid_url", default="Invalid URL format."))
|
||||||
return
|
return
|
||||||
|
|
||||||
save_dir = Path("images") / slug
|
save_dir = Path("analyses") / slug / "images"
|
||||||
|
|
||||||
self.start_btn.setEnabled(False)
|
self.start_btn.setEnabled(False)
|
||||||
self.url_input.setEnabled(False)
|
self.url_input.setEnabled(False)
|
||||||
|
|||||||
+6
-1
@@ -7,6 +7,10 @@ language = "en"
|
|||||||
reset_exclusions_on_image_change = false
|
reset_exclusions_on_image_change = false
|
||||||
# Hex color code for the match overlay (e.g. "#ff0000" for Red, "#00ff00" for Green)
|
# Hex color code for the match overlay (e.g. "#ff0000" for Red, "#00ff00" for Green)
|
||||||
overlay_color = "#ff0000"
|
overlay_color = "#ff0000"
|
||||||
|
# Hex color code for the background to be excluded (default #1f2937)
|
||||||
|
exclude_bg_color = "#1f2937"
|
||||||
|
# Tolerance for background color matching (0-255, default 5)
|
||||||
|
exclude_bg_tolerance = 5
|
||||||
|
|
||||||
[defaults]
|
[defaults]
|
||||||
# Override any of the following keys to tweak the initial slider values:
|
# Override any of the following keys to tweak the initial slider values:
|
||||||
@@ -15,6 +19,7 @@ overlay_color = "#ff0000"
|
|||||||
hue_min = 250.0
|
hue_min = 250.0
|
||||||
hue_max = 310.0
|
hue_max = 310.0
|
||||||
sat_min = 15.0
|
sat_min = 15.0
|
||||||
|
sat_max = 100.0
|
||||||
val_min = 15.0
|
val_min = 15.0
|
||||||
val_max = 100.0
|
val_max = 100.0
|
||||||
alpha = 120
|
alpha = 150
|
||||||
|
|||||||
+1
-1
@@ -4,7 +4,7 @@ version = "0.1.0"
|
|||||||
description = "Interactive Color Range Analyzer (ICRA) desktop app (PySide6)"
|
description = "Interactive Color Range Analyzer (ICRA) desktop app (PySide6)"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
authors = [{ name = "ICRA contributors" }]
|
authors = [{ name = "ICRA contributors" }]
|
||||||
license = "MIT"
|
license = "GPL-3.0-only"
|
||||||
requires-python = ">=3.10"
|
requires-python = ">=3.10"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"numpy>=1.26",
|
"numpy>=1.26",
|
||||||
|
|||||||
@@ -0,0 +1,72 @@
|
|||||||
|
import pytest
|
||||||
|
from pathlib import Path
|
||||||
|
from unittest.mock import MagicMock, patch
|
||||||
|
|
||||||
|
from PySide6 import QtWidgets
|
||||||
|
from app.qt.main_window import MainWindow
|
||||||
|
from app.qt.pattern_puller import PatternDownloadWorker
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def qt_app():
|
||||||
|
from PySide6.QtWidgets import QApplication
|
||||||
|
import sys
|
||||||
|
app = QApplication.instance()
|
||||||
|
if app is None:
|
||||||
|
app = QApplication(sys.argv)
|
||||||
|
yield app
|
||||||
|
|
||||||
|
|
||||||
|
def test_export_settings_path_generation(qt_app, tmp_path):
|
||||||
|
mock_widget = QtWidgets.QWidget()
|
||||||
|
mock_widget.title_label = MagicMock()
|
||||||
|
mock_widget.apply_theme = MagicMock()
|
||||||
|
with patch('app.qt.main_window.TitleBar', return_value=mock_widget):
|
||||||
|
window = MainWindow(language="en", defaults={}, reset_exclusions=False)
|
||||||
|
|
||||||
|
with patch("PySide6.QtWidgets.QFileDialog.getSaveFileName", return_value=("", "")) as mock_get_save:
|
||||||
|
|
||||||
|
# Test case 1: New subfolder structure (analyses/m4a1-s/images/1.png)
|
||||||
|
root = tmp_path / "analyses" / "m4a1_s"
|
||||||
|
img_dir = root / "images"
|
||||||
|
img_dir.mkdir(parents=True)
|
||||||
|
img_path = img_dir / "1.png"
|
||||||
|
|
||||||
|
window._current_image_path = img_path
|
||||||
|
window.export_settings()
|
||||||
|
|
||||||
|
# Verify settings directory was created
|
||||||
|
assert (root / "settings").exists()
|
||||||
|
|
||||||
|
# Verify default path given to QFileDialog
|
||||||
|
args, kwargs = mock_get_save.call_args
|
||||||
|
# args[2] is the default path string
|
||||||
|
expected_path = str(root / "settings" / "icra_settings_m4a1_s.json")
|
||||||
|
assert args[2] == expected_path
|
||||||
|
|
||||||
|
|
||||||
|
def test_export_folder_path_generation(qt_app, tmp_path):
|
||||||
|
mock_widget = QtWidgets.QWidget()
|
||||||
|
mock_widget.title_label = MagicMock()
|
||||||
|
mock_widget.apply_theme = MagicMock()
|
||||||
|
with patch('app.qt.main_window.TitleBar', return_value=mock_widget):
|
||||||
|
window = MainWindow(language="en", defaults={}, reset_exclusions=False)
|
||||||
|
|
||||||
|
with patch("PySide6.QtWidgets.QFileDialog.getSaveFileName", return_value=("", "")) as mock_get_save:
|
||||||
|
# Mock processor paths
|
||||||
|
root = tmp_path / "analyses" / "m4a1_s"
|
||||||
|
img_dir = root / "images"
|
||||||
|
img_dir.mkdir(parents=True)
|
||||||
|
window.processor.preview_paths = [img_dir / "1.png"]
|
||||||
|
|
||||||
|
window.export_folder()
|
||||||
|
|
||||||
|
assert (root / "results").exists()
|
||||||
|
args, kwargs = mock_get_save.call_args
|
||||||
|
expected_path = str(root / "results" / "icra_results_m4a1_s.csv")
|
||||||
|
assert args[2] == expected_path
|
||||||
|
|
||||||
|
|
||||||
|
def test_pattern_download_worker_dir(tmp_path):
|
||||||
|
worker = PatternDownloadWorker(slug="test-slug", save_dir=tmp_path / "analyses" / "test-slug" / "images")
|
||||||
|
assert worker.save_dir == tmp_path / "analyses" / "test-slug" / "images"
|
||||||
@@ -12,22 +12,24 @@ def test_stats_summary():
|
|||||||
matches_excl=10, total_excl=20
|
matches_excl=10, total_excl=20
|
||||||
)
|
)
|
||||||
|
|
||||||
# Mock translator
|
|
||||||
def mock_t(key, **kwargs):
|
def mock_t(key, **kwargs):
|
||||||
if key == "stats.placeholder":
|
if key == "stats.placeholder":
|
||||||
return "Placeholder"
|
return "Placeholder"
|
||||||
return f"{kwargs['with_pct']:.1f} {kwargs['without_pct']:.1f} {kwargs['excluded_pct']:.1f} {kwargs['excluded_match_pct']:.1f}"
|
if not kwargs:
|
||||||
|
return key
|
||||||
|
return f"{kwargs['with_pct']:.1f} {kwargs['without_pct']:.1f} {kwargs['excluded_pct']:.1f}"
|
||||||
|
|
||||||
res = s.summary(mock_t)
|
weights = {"match_all": 30, "match_keep": 50, "brightness": 10, "grouping": 10}
|
||||||
|
res = s.summary(mock_t, weights)
|
||||||
# with_pct: 40/80 = 50.0
|
# with_pct: 40/80 = 50.0
|
||||||
# without_pct: 50/100 = 50.0
|
# without_pct: 50/100 = 50.0
|
||||||
# excluded_pct: 20/100 = 20.0
|
# excluded_pct: 20/100 = 20.0
|
||||||
# excluded_match_pct: 10/20 = 50.0
|
assert res == "50.0 50.0 20.0"
|
||||||
assert res == "50.0 50.0 20.0 50.0"
|
|
||||||
|
|
||||||
def test_stats_empty():
|
def test_stats_empty():
|
||||||
s = Stats()
|
s = Stats()
|
||||||
assert s.summary(lambda k, **kw: "Empty") == "Empty"
|
weights = {"match_all": 30, "match_keep": 50, "brightness": 10, "grouping": 10}
|
||||||
|
assert s.summary(lambda k, **kw: "Empty", weights) == "Empty"
|
||||||
|
|
||||||
|
|
||||||
def test_rgb_to_hsv_numpy():
|
def test_rgb_to_hsv_numpy():
|
||||||
@@ -121,3 +123,35 @@ def test_coordinate_scaling():
|
|||||||
assert s_large.total_all == 1000000
|
assert s_large.total_all == 1000000
|
||||||
assert s_large.total_keep == 500000
|
assert s_large.total_keep == 500000
|
||||||
assert s_large.total_excl == 500000
|
assert s_large.total_excl == 500000
|
||||||
|
|
||||||
|
def test_calculate_grouping_score():
|
||||||
|
proc = QtImageProcessor()
|
||||||
|
|
||||||
|
# 1. Empty mask
|
||||||
|
mask_empty = np.zeros((20, 20), dtype=bool)
|
||||||
|
assert proc._calculate_grouping_score(mask_empty) == 0.0
|
||||||
|
|
||||||
|
# 2. Single mask pixel (0 neighbors)
|
||||||
|
mask_single = np.zeros((20, 20), dtype=bool)
|
||||||
|
mask_single[10, 10] = True
|
||||||
|
assert proc._calculate_grouping_score(mask_single) == 0.0
|
||||||
|
|
||||||
|
# 3. 2x2 block
|
||||||
|
# each pixel in 2x2 has 3 neighbors in 3x3, 3 neighbors in 5x5, 3 neighbors in 9x9.
|
||||||
|
# score = ((3/80)^2) * 100
|
||||||
|
expected_2x2 = ((3/80.0)**2) * 100.0
|
||||||
|
mask_block = np.zeros((20, 20), dtype=bool)
|
||||||
|
mask_block[10:12, 10:12] = True
|
||||||
|
assert pytest.approx(proc._calculate_grouping_score(mask_block)) == expected_2x2
|
||||||
|
|
||||||
|
# 4. 9x9 block
|
||||||
|
# center pixel has 80 neighbors (100% density).
|
||||||
|
# many pixels have high density.
|
||||||
|
mask_9x9 = np.zeros((20, 20), dtype=bool)
|
||||||
|
mask_9x9[5:14, 5:14] = True
|
||||||
|
res_9x9 = proc._calculate_grouping_score(mask_9x9)
|
||||||
|
assert res_9x9 > expected_2x2
|
||||||
|
# For a 9x9 block, the center pixel is 100%. Boundary pixels are less.
|
||||||
|
# 1 center pixel = 80/80 = 1.0.
|
||||||
|
# Overall it should be a healthy percentage.
|
||||||
|
assert res_9x9 > 10.0 # significant grouping
|
||||||
|
|||||||
Reference in New Issue
Block a user