Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
openbis
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
sispub
openbis
Commits
2bc0fd42
Commit
2bc0fd42
authored
13 years ago
by
brinn
Browse files
Options
Downloads
Patches
Plain Diff
add: method mixImages()
SVN: 22492
parent
121bc368
Loading
Loading
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
common/source/java/ch/systemsx/cisd/common/image/MixColors.java
+56
-3
56 additions, 3 deletions
.../source/java/ch/systemsx/cisd/common/image/MixColors.java
with
56 additions
and
3 deletions
common/source/java/ch/systemsx/cisd/common/image/MixColors.java
+
56
−
3
View file @
2bc0fd42
...
...
@@ -17,6 +17,7 @@
package
ch.systemsx.cisd.common.image
;
import
java.awt.Color
;
import
java.awt.image.BufferedImage
;
/**
* A class for calculating a mixed color from a set of pure colors of different relative
...
...
@@ -30,7 +31,7 @@ public class MixColors
{
private
static
final
int
MAX_COMPONENT_VALUE
=
255
;
private
static
final
float
MAX_COMPONENT_VALUE_FLOAT
=
MAX_COMPONENT_VALUE
;
private
static
int
getMaxComponent
(
int
r
,
int
g
,
int
b
)
...
...
@@ -74,7 +75,7 @@ public class MixColors
private
static
Color
getColor
(
float
red
,
float
green
,
float
blue
,
int
brightness
)
{
final
float
max
=
getMaxComponent
(
red
,
green
,
blue
);
// Normalize the brightness.
// Normalize the brightness.
final
float
normFactor
=
Math
.
min
(
MAX_COMPONENT_VALUE_FLOAT
,
brightness
)
/
max
;
red
*=
normFactor
;
green
*=
normFactor
;
...
...
@@ -103,7 +104,7 @@ public class MixColors
private
static
Color
getColor
(
int
red
,
int
green
,
int
blue
,
int
brightness
)
{
final
int
max
=
getMaxComponent
(
red
,
green
,
blue
);
// Normalize the brightness.
// Normalize the brightness.
final
float
normFactor
=
Math
.
min
(
MAX_COMPONENT_VALUE_FLOAT
,
brightness
)
/
max
;
red
=
Math
.
round
(
red
*
normFactor
);
green
=
Math
.
round
(
green
*
normFactor
);
...
...
@@ -233,4 +234,56 @@ public class MixColors
return
getColor
(
red
,
green
,
blue
);
}
/**
* Calculate a new image by mixing the given gray-scale </var>images</var>.
*
* @param images The images to merge.
* @param quadratic If <code>true</code>, use a quadratic (weighted) additive color mixture,
* otherwise use a linear (unweighted) additive color mixture.
* @param saturationEnhancementFactor If > 0, perform a saturation enhancement step with the
* given factor.
* @return Returns the mixed image.
*/
public
static
BufferedImage
mixImages
(
BufferedImage
[]
images
,
Color
[]
colors
,
boolean
quadratic
,
float
saturationEnhancementFactor
)
{
for
(
int
i
=
0
;
i
<
images
.
length
;
++
i
)
{
if
(
images
[
i
].
getColorModel
().
getNumColorComponents
()
!=
1
||
images
[
i
].
getColorModel
().
getComponentSize
(
0
)
!=
8
)
{
throw
new
IllegalArgumentException
(
"mixImages() only works on 8-bit gray scale images."
);
}
}
final
BufferedImage
mixed
=
new
BufferedImage
(
images
[
0
].
getWidth
(),
images
[
0
].
getHeight
(),
BufferedImage
.
TYPE_INT_RGB
);
for
(
int
x
=
0
;
x
<
images
[
0
].
getWidth
();
++
x
)
{
for
(
int
y
=
0
;
y
<
images
[
0
].
getHeight
();
++
y
)
{
final
float
[]
intensities
=
new
float
[
images
.
length
];
for
(
int
i
=
0
;
i
<
images
.
length
;
++
i
)
{
intensities
[
i
]
=
images
[
i
].
getRaster
().
getSampleFloat
(
x
,
y
,
0
)
/
255
f
;
}
Color
mixColor
=
quadratic
?
calcMixedColorQuadratic
(
colors
,
intensities
)
:
calcMixedColorLinear
(
colors
,
intensities
);
if
(
saturationEnhancementFactor
>
0
f
)
{
final
float
[]
hsb
=
Color
.
RGBtoHSB
(
mixColor
.
getRed
(),
mixColor
.
getGreen
(),
mixColor
.
getBlue
(),
null
);
mixColor
=
Color
.
getHSBColor
(
hsb
[
0
],
Math
.
min
(
1
f
,
saturationEnhancementFactor
*
hsb
[
1
]),
hsb
[
2
]);
}
mixed
.
setRGB
(
x
,
y
,
mixColor
.
getRGB
());
}
}
return
mixed
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment