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
fb4557a2
Commit
fb4557a2
authored
13 years ago
by
tpylak
Browse files
Options
Downloads
Patches
Plain Diff
LMS-2526 minor refactoring
SVN: 23095
parent
89f6be61
No related branches found
No related tags found
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
+60
-16
60 additions, 16 deletions
.../source/java/ch/systemsx/cisd/common/image/MixColors.java
with
60 additions
and
16 deletions
common/source/java/ch/systemsx/cisd/common/image/MixColors.java
+
60
−
16
View file @
fb4557a2
...
@@ -208,6 +208,11 @@ public class MixColors
...
@@ -208,6 +208,11 @@ public class MixColors
red
+=
r
;
red
+=
r
;
green
+=
g
;
green
+=
g
;
blue
+=
b
;
blue
+=
b
;
// red = Math.max(red, r);
// green = Math.max(green, g);
// blue = Math.max(blue, b);
}
}
return
getColor
(
red
,
green
,
blue
);
return
getColor
(
red
,
green
,
blue
);
}
}
...
@@ -236,6 +241,11 @@ public class MixColors
...
@@ -236,6 +241,11 @@ public class MixColors
return
getColor
(
red
,
green
,
blue
);
return
getColor
(
red
,
green
,
blue
);
}
}
private
static
interface
ColorMergingAlgorithm
{
Color
merge
(
Color
[]
colors
,
float
[]
intensities
);
}
/**
/**
* Calculate a new image by mixing the given gray-scale </var>images</var>.
* Calculate a new image by mixing the given gray-scale </var>images</var>.
*
*
...
@@ -251,6 +261,8 @@ public class MixColors
...
@@ -251,6 +261,8 @@ public class MixColors
{
{
assert
colors
.
length
==
images
.
length
:
"number of colors and images do not match"
;
assert
colors
.
length
==
images
.
length
:
"number of colors and images do not match"
;
ColorMergingAlgorithm
mergeColorsAlgorithm
=
createColorMergingAlgorithm
(
quadratic
,
saturationEnhancementFactor
);
for
(
int
i
=
0
;
i
<
images
.
length
;
++
i
)
for
(
int
i
=
0
;
i
<
images
.
length
;
++
i
)
{
{
if
(
images
[
i
].
getColorModel
().
getNumColorComponents
()
!=
1
if
(
images
[
i
].
getColorModel
().
getNumColorComponents
()
!=
1
...
@@ -260,34 +272,66 @@ public class MixColors
...
@@ -260,34 +272,66 @@ public class MixColors
"mixImages() only works on 8-bit gray scale images."
);
"mixImages() only works on 8-bit gray scale images."
);
}
}
}
}
final
BufferedImage
mixed
=
int
width
=
images
[
0
].
getWidth
();
new
BufferedImage
(
images
[
0
].
getWidth
(),
images
[
0
].
getHeight
(),
int
height
=
images
[
0
].
getHeight
();
BufferedImage
.
TYPE_INT_RGB
);
final
BufferedImage
mixed
=
new
BufferedImage
(
width
,
height
,
BufferedImage
.
TYPE_INT_RGB
);
final
float
[]
intensities
=
new
float
[
images
.
length
];
for
(
int
y
=
0
;
y
<
images
[
0
].
getHeight
();
++
y
)
for
(
int
y
=
0
;
y
<
images
[
0
].
getHeight
();
++
y
)
{
{
for
(
int
x
=
0
;
x
<
images
[
0
].
getWidth
();
++
x
)
for
(
int
x
=
0
;
x
<
images
[
0
].
getWidth
();
++
x
)
{
{
final
float
[]
intensities
=
new
float
[
images
.
length
];
for
(
int
i
=
0
;
i
<
images
.
length
;
++
i
)
for
(
int
i
=
0
;
i
<
images
.
length
;
++
i
)
{
{
intensities
[
i
]
=
images
[
i
].
getRaster
().
getSampleFloat
(
x
,
y
,
0
)
/
255
f
;
intensities
[
i
]
=
images
[
i
].
getRaster
().
getSampleFloat
(
x
,
y
,
0
)
/
255
f
;
}
}
Color
mixColor
=
Color
mixColor
=
mergeColorsAlgorithm
.
merge
(
colors
,
intensities
);
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
());
mixed
.
setRGB
(
x
,
y
,
mixColor
.
getRGB
());
}
}
}
}
return
mixed
;
return
mixed
;
}
}
private
static
Color
saturate
(
float
saturationEnhancementFactor
,
Color
mixColor
)
{
final
float
[]
hsb
=
Color
.
RGBtoHSB
(
mixColor
.
getRed
(),
mixColor
.
getGreen
(),
mixColor
.
getBlue
(),
null
);
return
Color
.
getHSBColor
(
hsb
[
0
],
Math
.
min
(
1
f
,
saturationEnhancementFactor
*
hsb
[
1
]),
hsb
[
2
]);
}
private
static
ColorMergingAlgorithm
createColorMergingAlgorithm
(
boolean
quadratic
,
final
float
saturationEnhancementFactor
)
{
if
(
quadratic
)
{
return
new
ColorMergingAlgorithm
()
{
public
Color
merge
(
Color
[]
colors
,
float
[]
intensities
)
{
Color
color
=
calcMixedColorQuadratic
(
colors
,
intensities
);
if
(
saturationEnhancementFactor
>
0
)
{
color
=
saturate
(
saturationEnhancementFactor
,
color
);
}
return
color
;
}
};
}
else
{
return
new
ColorMergingAlgorithm
()
{
public
Color
merge
(
Color
[]
colors
,
float
[]
intensities
)
{
Color
color
=
calcMixedColorLinear
(
colors
,
intensities
);
if
(
saturationEnhancementFactor
>
0
)
{
color
=
saturate
(
saturationEnhancementFactor
,
color
);
}
return
color
;
}
};
}
}
}
}
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