Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
lafabregue
MultiCube
Commits
5b0f182c
Commit
5b0f182c
authored
Aug 04, 2017
by
lafabregue
Browse files
implemntation of the version with bufferedImage
parent
11dbff3d
Changes
10
Expand all
Hide whitespace changes
Inline
Side-by-side
src/mustic/gui/ClassList.java
View file @
5b0f182c
...
...
@@ -223,8 +223,7 @@ public class ClassList {
this
.
imageSession
.
mImagePanel
.
supprimePoint
(
x
,
y
,
this
.
imageSession
.
getPixelColor
(
x
,
y
));
this
.
imageSession
.
mImagePanel
.
updateImageView
(
this
.
imageSession
.
mImagePanel
.
getmScreenImage
());
.
updateImageView
();
}
}
/** The user choose to create a zone */
...
...
@@ -542,8 +541,7 @@ public class ClassList {
this
.
deleteCollectionOfPoints
(
vp
);
fillListOfDrawnPoints
();
this
.
imageSession
.
mImagePanel
.
updateImageView
(
this
.
imageSession
.
mImagePanel
.
getmScreenImage
());
.
updateImageView
();
}
/**
...
...
@@ -684,8 +682,7 @@ public class ClassList {
this
.
imageSession
.
getPixelColor
(
pt
.
x
,
pt
.
y
));
}
fillListOfDrawnPoints
();
imageSession
.
mImagePanel
.
updateImageView
(
imageSession
.
mImagePanel
.
getmScreenImage
());
imageSession
.
mImagePanel
.
updateImageView
();
}
/**
...
...
@@ -880,8 +877,7 @@ public class ClassList {
this
.
imageSession
.
getPixelColor
(
pt
.
x
,
pt
.
y
));
}
fillListOfDrawnPoints
();
imageSession
.
mImagePanel
.
updateImageView
(
imageSession
.
mImagePanel
.
getmScreenImage
());
imageSession
.
mImagePanel
.
updateImageView
();
}
/**
...
...
@@ -1051,8 +1047,7 @@ public class ClassList {
this
.
imageSession
.
getPixelColor
(
pt
.
x
,
pt
.
y
));
}
fillListOfDrawnPoints
();
imageSession
.
mImagePanel
.
updateImageView
(
imageSession
.
mImagePanel
.
getmScreenImage
());
imageSession
.
mImagePanel
.
updateImageView
();
}
/**
...
...
src/mustic/gui/ImageSession.java
View file @
5b0f182c
...
...
@@ -66,7 +66,7 @@ public class ImageSession {
public
SSHParameters
sshparameters
=
null
;
/** enable the image to display the image or not, for a memory usage matter */
private
boolean
displayEnable
=
fals
e
;
private
boolean
displayEnable
=
tru
e
;
/**
* @param aImage
...
...
@@ -105,7 +105,7 @@ public class ImageSession {
/**
* creation ImagePane
*/
this
.
mImagePanel
=
new
ImagePanel
(
aImage
);
this
.
mImagePanel
=
new
ImagePanel
(
aImage
,
this
);
if
(
MainFrame
.
DEBUG_MODE
)
System
.
out
.
println
(
Messages
.
getString
(
"ImageSession.4"
));
//$NON-NLS-1$
...
...
@@ -121,12 +121,11 @@ public class ImageSession {
if
(
MainFrame
.
DEBUG_MODE
)
System
.
out
.
println
(
Messages
.
getString
(
"ImageSession.6"
));
//$NON-NLS-1$
this
.
mWorskSpace
=
new
TabbedPanel
();
JScrollPane
sp
=
new
JScrollPane
(
this
.
mImagePanel
);
final
TitledTab
tabImage
=
TabFactory
.
createTitledTab
(
"Image"
,
new
ImageIcon
(
getClass
().
getResource
(
"/icons/mimetypes/image-x-generic.png"
)),
sp
);
this
.
mImagePanel
);
// mWorskSpace = new JPanel(new BorderLayout());
mWorskSpace
.
addTab
(
tabImage
);
...
...
@@ -271,7 +270,7 @@ public class ImageSession {
if
(
displayEnable
)
{
this
.
mImagePanel
.
applyMask
(
this
.
rawImage
.
getMask
());
this
.
mImagePanel
.
doZoomOp
();
this
.
mImagePanel
.
refresh
();
}
}
...
...
src/mustic/gui/ListOfPolygon.java
View file @
5b0f182c
...
...
@@ -89,8 +89,7 @@ public class ListOfPolygon {
}
}
removePolygon
(
plg
);
areasLst
.
getImagePanel
().
updateImageView
(
areasLst
.
getImagePanel
().
getmScreenImage
());
areasLst
.
getImagePanel
().
updateImageView
();
}
}
...
...
src/mustic/gui/MainFrame.java
View file @
5b0f182c
...
...
@@ -84,27 +84,27 @@ public class MainFrame extends JFrame {
/*
* temporary files directory Always check the directory existence or create it
*/
private
static
final
String
TMP_DIR_PATH
=
"temporary"
;
private
static
final
File
TMP_DIR_FILE
=
new
File
(
TMP_DIR_PATH
);
private
static
final
String
TMP_DIR_PATH
=
"temporary"
;
private
static
final
File
TMP_DIR_FILE
=
new
File
(
TMP_DIR_PATH
);
/** l'instance unique de ce singleton */
private
static
MainFrame
instance
=
null
;
private
static
MainFrame
instance
=
null
;
public
final
static
boolean
DEBUG_MODE
=
true
;
public
final
static
boolean
DEBUG_MODE
=
true
;
/** La barre de progression */
private
static
JProgressBar
progressBar
=
new
JProgressBar
();
private
static
JProgressBar
progressBar
=
new
JProgressBar
();
/** */
private
static
final
long
serialVersionUID
=
1L
;
private
static
final
long
serialVersionUID
=
1L
;
/** barre d'etat */
private
static
ProgressStatus
progressStatus
=
new
ProgressStatus
();
private
static
boolean
targetMode
=
true
;
private
static
ProgressStatus
progressStatus
=
new
ProgressStatus
();
private
static
boolean
targetMode
=
true
;
/** panel pour l'affichage du birdview de l'image selectionnee */
private
JPanel
birdPanel
;
private
File
currentDirectory
=
null
;
private
File
currentDirectory
=
null
;
/** l'image courante selectionne */
private
ImageSession
currentImageSession
;
...
...
@@ -114,7 +114,7 @@ public class MainFrame extends JFrame {
/**
* bureau pour internal frame (une DesktopFrame (extends JInternalFrame) par image)
*/
private
MusticDesktop
desktop
=
null
;
private
MusticDesktop
desktop
=
null
;
/** repertoire contenant l'aide */
private
String
helpPath
=
"/docs/help"
;
//$NON-NLS-1$
...
...
@@ -146,25 +146,25 @@ public class MainFrame extends JFrame {
/**
* Nombre de threads
*/
public
int
nbThreads
=
Runtime
.
getRuntime
().
availableProcessors
();
public
int
nbThreads
=
Runtime
.
getRuntime
().
availableProcessors
();
/** panel de la toolbar */
private
JPanel
northPanel
=
new
JPanel
(
new
BorderLayout
());
private
JPanel
northPanel
=
new
JPanel
(
new
BorderLayout
());
/**
* <p>
* Affiche une fenetre permettant de faire une segmentation
* </p>
*/
private
JPanel
panelResSave
=
new
JPanel
();
private
JPanel
panelResSave
=
new
JPanel
();
private
JInternalFrame
resultSaveTextField
=
new
JInternalFrame
();
private
JInternalFrame
resultSaveTextField
=
new
JInternalFrame
();
/**
* Indique si l'orthorectification doit etre lancee par mustic ou non
* Desactive par defaut
*/
private
boolean
launchOrthoRect
=
false
;
private
boolean
launchOrthoRect
=
false
;
/**
* <p>
...
...
@@ -2767,7 +2767,7 @@ public class MainFrame extends JFrame {
MainFrame
.
this
.
currentImageSession
.
getBirdViewPanel
().
refresh
();
this
.
getProgressBar
().
setValue
(
100
);
}
this
.
currentImageSession
.
getBirdViewPanel
().
syncImage
(
this
.
currentImageSession
);
this
.
currentImageSession
.
getBirdViewPanel
().
syncImage
();
this
.
getProgressBar
().
setValue
(
0
);
endTime
=
System
.
currentTimeMillis
();
if
(
MainFrame
.
DEBUG_MODE
)
...
...
src/mustic/gui/panels/BirdViewPanel.java
View file @
5b0f182c
...
...
@@ -65,9 +65,7 @@ public class BirdViewPanel extends JPanel implements MouseListener,
/** Represents the initial selction area. */
private
Rectangle
initArea
=
new
Rectangle
();
private
double
max
[];
// max value for each band
/** The Image */
private
BufferedImage
mBirdImage
;
...
...
@@ -77,6 +75,8 @@ public class BirdViewPanel extends JPanel implements MouseListener,
/** Represents the panel which display the selection area */
private
ImagePanel
mImagePanel
;
private
double
max
[];
// max value for each band
private
double
min
[];
// min value for each band
/** Info */
private
ImageInformationPanel
mInfoPanel
;
...
...
@@ -718,6 +718,34 @@ public class BirdViewPanel extends JPanel implements MouseListener,
// draw the buffer
g
.
drawImage
(
this
.
offscreenImage
,
0
,
0
,
null
);
}
/**
* Update the selection area in the BirdViewPanel to match a new
* selection
*
* @param x
* X coordinate in the original image
* @param y
* Y coordinate in the original image
* @param width
* width in the original image
* @param height
* height in the original image
*/
public
void
updateSelectedArea
(
int
x
,
int
y
,
int
width
,
int
height
)
{
Picture
birdview
=
this
.
mImage
.
getBirdview
();
double
xfact
=
(
double
)
this
.
mImage
.
getWidth
()
/
(
double
)
birdview
.
getImage
().
getWidth
();
double
yfact
=
(
double
)
this
.
mImage
.
getHeight
()
/
(
double
)
birdview
.
getImage
().
getHeight
();
int
sx
=
(
int
)
(
x
/
xfact
);
int
sy
=
(
int
)
(
y
/
yfact
);
int
swidth
=
(
int
)
Math
.
ceil
(
width
/
xfact
);
int
sheight
=
(
int
)
Math
.
ceil
(
height
/
yfact
);
this
.
selArea
=
new
Rectangle
(
sx
,
sy
,
swidth
,
sheight
);
refresh
();
}
public
void
refresh
()
{
if
(!
session
.
isDisplayEnable
())
...
...
@@ -745,6 +773,9 @@ public class BirdViewPanel extends JPanel implements MouseListener,
this
.
bImage
=
img
;
}
/**
* Synchronize the ImagePanel to the BirdViewPanel selection
*/
public
void
syncImage
()
{
if
(!
session
.
isDisplayEnable
())
return
;
...
...
@@ -760,85 +791,7 @@ public class BirdViewPanel extends JPanel implements MouseListener,
int
width
=
(
int
)
Math
.
ceil
(
this
.
selArea
.
width
*
xfact
);
int
height
=
(
int
)
Math
.
ceil
(
this
.
selArea
.
height
*
yfact
);
Rectangle
realarea
=
new
Rectangle
(
rx
,
ry
,
width
,
height
);
double
data
[][][]
=
this
.
mImage
.
load
(
realarea
.
x
,
realarea
.
y
,
realarea
.
width
,
realarea
.
height
);
double
values
[][]
=
data
[
0
];
BufferedImage
image
=
new
BufferedImage
(
realarea
.
width
,
realarea
.
height
,
BufferedImage
.
TYPE_INT_RGB
);
this
.
bImage
=
new
BufferedImage
(
realarea
.
width
,
realarea
.
height
,
BufferedImage
.
TYPE_INT_RGB
);
if
(
this
.
max
==
null
||
this
.
min
==
null
)
{
for
(
int
x
=
0
;
x
<
values
.
length
;
x
++)
{
for
(
int
y
=
0
;
y
<
values
[
0
].
length
;
y
++)
{
int
pixel
=
(
int
)
values
[
x
][
y
]
<<
24
|
(
int
)
data
[
this
.
r
][
x
][
y
]
<<
16
|
(
int
)
data
[
this
.
g
][
x
][
y
]
<<
8
|
(
int
)
data
[
this
.
b
][
x
][
y
];
image
.
setRGB
(
x
,
y
,
pixel
);
this
.
bImage
.
setRGB
(
x
,
y
,
pixel
);
}
}
}
else
{
short
[][][]
dataView
=
new
short
[
data
.
length
][
data
[
0
].
length
][
data
[
0
][
0
].
length
];
;
// the values to display
int
i
;
// r g b
int
[]
bands
=
new
int
[
3
];
bands
[
0
]
=
this
.
r
;
bands
[
1
]
=
this
.
g
;
bands
[
2
]
=
this
.
b
;
/*
* max contains the max value for r g b, we can create a valid
* representation of data. the data values must be between 0 and 255
* to be valid, so let's convert them if needed
*/
for
(
int
b
=
0
;
b
<
bands
.
length
;
b
++)
{
i
=
bands
[
b
];
for
(
int
x
=
0
;
x
<
data
[
0
].
length
;
x
++)
{
for
(
int
y
=
0
;
y
<
data
[
0
][
0
].
length
;
y
++)
{
if
(
data
[
i
][
x
][
y
]
>
0
)
{
// convert only if needed to avoid color deformation
// on 8 bits images
if
(
this
.
max
[
i
]
<=
255
&&
this
.
min
[
i
]
>=
0
)
{
dataView
[
i
][
x
][
y
]
=
(
short
)
data
[
i
][
x
][
y
];
}
else
{
dataView
[
i
][
x
][
y
]
=
(
short
)
(
255
*
(
data
[
i
][
x
][
y
]
-
this
.
min
[
i
])
/
(
this
.
max
[
i
]
-
this
.
min
[
i
]));
}
}
else
{
dataView
[
i
][
x
][
y
]
=
0
;
}
}
}
}
// pixels of the image to display
for
(
int
x
=
0
;
x
<
values
.
length
;
x
++)
{
for
(
int
y
=
0
;
y
<
values
[
0
].
length
;
y
++)
{
int
pixel
=
(
int
)
values
[
x
][
y
]
<<
24
|
dataView
[
this
.
r
][
x
][
y
]
<<
16
|
dataView
[
this
.
g
][
x
][
y
]
<<
8
|
dataView
[
this
.
b
][
x
][
y
];
image
.
setRGB
(
x
,
y
,
pixel
);
//
this
.
bImage
.
setRGB
(
x
,
y
,
pixel
);
//
}
}
}
this
.
mImage
.
afficheRoi
(
image
,
rx
,
ry
);
this
.
mImagePanel
.
setImage
(
image
);
this
.
mImagePanel
.
updateImageViewTo
(
rx
,
ry
,
width
,
height
);
this
.
rxsave
=
rx
;
this
.
rysave
=
ry
;
...
...
@@ -846,6 +799,11 @@ public class BirdViewPanel extends JPanel implements MouseListener,
}
/**
* Synchronize an ImagePanel to the BirdViewPanel selection
*
* @param session the ImageSession to be synchronized
*/
synchronized
public
void
syncImage
(
ImageSession
session
)
{
if
(!
session
.
isDisplayEnable
())
...
...
@@ -902,88 +860,7 @@ public class BirdViewPanel extends JPanel implements MouseListener,
if
(
ry
<
0
)
ry
=
0
;
Rectangle
realarea
=
new
Rectangle
(
rx
,
ry
,
width
,
height
);
double
data
[][][]
=
session
.
getRawImage
().
load
(
realarea
.
x
,
realarea
.
y
,
realarea
.
width
,
realarea
.
height
);
double
values
[][]
=
data
[
0
];
BufferedImage
image
=
new
BufferedImage
(
realarea
.
width
,
realarea
.
height
,
BufferedImage
.
TYPE_INT_RGB
);
this
.
bImage
=
new
BufferedImage
(
realarea
.
width
,
realarea
.
height
,
BufferedImage
.
TYPE_INT_RGB
);
short
[][][]
dataView
=
new
short
[
data
.
length
][
data
[
0
].
length
][
data
[
0
][
0
].
length
];
;
// the values to display
int
i
;
// r g b
int
[]
bands
=
new
int
[
3
];
bands
[
0
]
=
session
.
getBirdViewPanel
().
r
;
bands
[
1
]
=
session
.
getBirdViewPanel
().
g
;
bands
[
2
]
=
session
.
getBirdViewPanel
().
b
;
/*
* max contains the max value for r g b, we can create a valid
* representation of data. the data values must be between 0 and 255 to
* be valid, so let's convert them if needed
*/
for
(
int
b
=
0
;
b
<
bands
.
length
;
b
++)
{
i
=
bands
[
b
];
for
(
int
x
=
0
;
x
<
data
[
0
].
length
;
x
++)
{
for
(
int
y
=
0
;
y
<
data
[
0
][
0
].
length
;
y
++)
{
if
(
data
[
i
][
x
][
y
]
>
0
)
{
// convert only if needed to avoid color deformation on
// 8 bits images
if
(
session
.
getBirdViewPanel
().
max
[
i
]
<=
255
&&
session
.
getBirdViewPanel
().
min
[
i
]
>=
0
)
{
dataView
[
i
][
x
][
y
]
=
(
short
)
data
[
i
][
x
][
y
];
}
else
{
dataView
[
i
][
x
][
y
]
=
(
short
)
(
255
*
(
data
[
i
][
x
][
y
]
-
session
.
getBirdViewPanel
().
min
[
i
])
/
(
session
.
getBirdViewPanel
().
max
[
i
]
-
session
.
getBirdViewPanel
().
min
[
i
]));
}
}
else
{
dataView
[
i
][
x
][
y
]
=
0
;
}
}
}
}
// pixels of the image to display
for
(
int
x
=
0
;
x
<
values
.
length
;
x
++)
{
for
(
int
y
=
0
;
y
<
values
[
0
].
length
;
y
++)
{
int
pixel
=
(
int
)
values
[
x
][
y
]
<<
24
|
dataView
[
session
.
getBirdViewPanel
().
r
][
x
][
y
]
<<
16
|
dataView
[
session
.
getBirdViewPanel
().
g
][
x
][
y
]
<<
8
|
dataView
[
session
.
getBirdViewPanel
().
b
][
x
][
y
];
image
.
setRGB
(
x
,
y
,
pixel
);
//
this
.
bImage
.
setRGB
(
x
,
y
,
pixel
);
//
}
}
session
.
getBirdViewPanel
().
selArea
.
x
=
(
int
)
Math
.
round
(
rx
/
xfact
);
session
.
getBirdViewPanel
().
selArea
.
y
=
(
int
)
Math
.
round
(
ry
/
yfact
);
session
.
getBirdViewPanel
().
selArea
.
width
=
this
.
selArea
.
width
;
session
.
getBirdViewPanel
().
selArea
.
height
=
this
.
selArea
.
height
;
session
.
getBirdViewPanel
().
xsave
=
(
int
)
Math
.
round
(
rx
/
xfact
);
session
.
getBirdViewPanel
().
ysave
=
(
int
)
Math
.
round
(
ry
/
yfact
);
session
.
getBirdViewPanel
().
xxsave
=
realarea
.
x
;
session
.
getBirdViewPanel
().
yysave
=
realarea
.
y
;
session
.
getBirdViewPanel
().
rxsave
=
rx
;
session
.
getBirdViewPanel
().
rysave
=
ry
;
session
.
getRawImage
().
afficheRoi
(
image
,
rx
,
ry
);
session
.
getImagePanel
().
setImage
(
image
);
this
.
session
.
getImagePanel
().
updateImageViewTo
(
rx
,
ry
,
width
,
height
);
//TODO do the same for the DataSession
// for (ImageResultPanel resultPanel : session.getResultPanels()) {
...
...
@@ -991,7 +868,7 @@ public class BirdViewPanel extends JPanel implements MouseListener,
// }
for
(
SegmentationPanel
segPanel
:
session
.
getSegPanels
())
{
segPanel
.
setImage
(
image
,
rx
,
ry
);
segPanel
.
setImage
(
this
.
session
.
getImagePanel
().
getImage
()
,
rx
,
ry
);
}
//
...
...
src/mustic/gui/panels/ImagePanel.java
View file @
5b0f182c
This diff is collapsed.
Click to expand it.
src/mustic/gui/segmentation/SegmentationPanel.java
View file @
5b0f182c
...
...
@@ -102,7 +102,7 @@ public class SegmentationPanel extends JPanel implements ActionListener, MouseLi
this
.
mZoomRate
=
MainFrame
.
getInstance
().
getCurrentImageSession
().
getImagePanel
().
getZoomRate
();
this
.
mZoomStep
=
MainFrame
.
getInstance
().
getCurrentImageSession
().
getImagePanel
().
getmZoomStep
();
this
.
offset
=
MainFrame
.
getInstance
().
getCurrentImageSession
().
getImagePanel
().
getBrightnessValue
();
this
.
offsetStep
=
MainFrame
.
getInstance
().
getCurrentImageSession
().
getImagePanel
().
get
Offset
Step
();
this
.
offsetStep
=
MainFrame
.
getInstance
().
getCurrentImageSession
().
getImagePanel
().
get
Brightness
Step
();
this
.
scaleFactor
=
MainFrame
.
getInstance
().
getCurrentImageSession
().
getImagePanel
().
getScaleFactor
();
this
.
scaleFactorStep
=
MainFrame
.
getInstance
().
getCurrentImageSession
().
getImagePanel
().
getScaleFactorStep
();
...
...
src/mustic/utils/image/BufferedImageHelper.java
0 → 100644
View file @
5b0f182c
package
mustic.utils.image
;
import
java.awt.Color
;
import
java.awt.Point
;
import
java.awt.image.BufferedImage
;
import
java.awt.image.ColorModel
;
import
java.awt.image.DirectColorModel
;
import
java.awt.image.Raster
;
import
java.awt.image.SampleModel
;
import
java.awt.image.SinglePixelPackedSampleModel
;
import
java.awt.image.WritableRaster
;
/**
* Class that allows buffer manipulation and creation from images.
* This class use bio-format library to read images and works only
* with BuffredImage using DirectColorModel and SinglePixelPaxedSampleModel.
* There not yet any support for other format, and it is not likely
* to works if the format is different.
*
* @author Baptiste LAFABREGUE
*
*/
public
class
BufferedImageHelper
{
/**
* Transform an image on short array format into a RGB BufferedImage
* The raster should follow the order bellow :
* short[channel][x][y]
*
* @param raster
* an image raster to convert to bufferImage
* @param r
* the index of the red channel
* @param g
* the index of the green channel
* @param b
* the index of the blue channel
* @return the corresponding BufferdImage
*/
public
static
BufferedImage
createBufferedImageFromImage
(
short
[][][]
raster
,
int
r
,
int
g
,
int
b
)
{
if
(
r
<
0
||
r
>=
raster
.
length
||
g
<
0
||
g
>=
raster
.
length
||
b
<
0
||
b
>=
raster
.
length
)
{
throw
new
IndexOutOfBoundsException
(
"R, G and B index should respect"
+
" the number of channels in the image."
);
}
DirectColorModel
cm
=
(
DirectColorModel
)
DirectColorModel
.
getRGBdefault
();
WritableRaster
ra
=
cm
.
createCompatibleWritableRaster
(
raster
[
0
].
length
,
raster
[
0
][
0
].
length
);
BufferedImage
result
=
new
BufferedImage
(
cm
,
ra
,
false
,
null
);
for
(
int
x
=
0
;
x
<
raster
[
0
].
length
;
x
++)
{
for
(
int
y
=
0
;
y
<
raster
[
0
][
0
].
length
;
y
++)
{
// int rgb = (raster[r][x][y] << 16)
// & (raster[g][x][y] << 8)
// & (raster[b][x][y]);
int
rgb
=
new
Color
(
raster
[
r
][
x
][
y
],
raster
[
g
][
x
][
y
],
raster
[
b
][
x
][
y
]).
getRGB
();
result
.
setRGB
(
x
,
y
,
rgb
);
}
}
return
result
;
}
/**
* Return the list of all min/max for each channel in an image raster.
* The raster should follow the order bellow :
* short[channel][x][y]
* The result have the format bellow :
* [channel][0] = min
* [channel][1] = max
*
* @param raster
* the raster to evaluate
* @return the list of min/max per channel
*/
public
static
double
[][]
computeMinMax
(
double
[][][]
raster
)
{
double
[][]
result
=
new
double
[
raster
.
length
][
2
];
for
(
int
c
=
0
;
c
<
raster
.
length
;
c
++)
{
double
min
=
raster
[
c
][
0
][
0
];
double
max
=
raster
[
c
][
0
][
0
];
for
(
int
x
=
0
;
x
<
raster
[
0
].
length
;
x
++)
{
for
(
int
y
=
0
;
y
<
raster
[
0
][
0
].
length
;
y
++)
{
if
(
raster
[
c
][
x
][
y
]
<
min
)
{
min
=
raster
[
c
][
x
][
y
];
}
else
if
(
raster
[
c
][
x
][
y
]
>
max
)
{
max
=
raster
[
c
][
x
][
y
];
}
}
}
result
[
c
][
0
]
=
min
;
result
[
c
][
1
]
=
max
;
}
return
result
;
}
/**
* Change the order of the channels, this function is only available
* for BufferedImage using DirectColorModel and SinglePixelPaxedSampleModel.
* Channels indexes should go from 0 to 2.
*
* @param buffer
* the BufferedImage used to get the DataBuffer of the new BufferedImage
* @param nr
* the red channel position in the new BufferedImage
* @param ng
* the green channel position in the new BufferedImage
* @param nb
* the blue channel position in the new BufferedImage
* @return the new BufferedImage
*/
public
static
BufferedImage
swapChannels
(
BufferedImage
buffer
,
int
nr
,
int
ng
,
int
nb
)
{
int
bits
=
((
DirectColorModel
)
buffer
.
getColorModel
()).
getPixelSize
();
int
[]
rgb
=
new
int
[
3
];
rgb
[
nr
]
=
((
DirectColorModel
)
buffer
.
getColorModel
()).
getRedMask
();
rgb
[
ng
]
=
((
DirectColorModel
)
buffer
.
getColorModel
()).
getGreenMask
();
rgb
[
nb
]
=
((
DirectColorModel
)
buffer
.
getColorModel
()).
getBlueMask
();
ColorModel
cm
=
new
DirectColorModel
(
bits
,
rgb
[
0
],
rgb
[
1
],
rgb
[
2
]);
SampleModel
sm
=
new
SinglePixelPackedSampleModel
(
buffer
.
getSampleModel
().
getDataType
(),
buffer
.
getWidth
(),
buffer
.
getHeight
(),
rgb
);
WritableRaster
ra
=
(
WritableRaster
)
Raster
.
createRaster
(
sm
,
buffer
.
getRaster
()
.
getDataBuffer
(),
new
Point
(
0
,
0
));
return
new
BufferedImage
(
cm
,
ra
,
false
,
null
);
}
}
src/mustic/utils/image/BufferedImageViewer.java
View file @
5b0f182c
package
mustic.utils.image
;
import
java.awt.geom.AffineTransform
;
import
java.awt.image.AffineTransformOp
;
import
java.awt.image.BufferedImage
;
import
java.awt.image.RescaleOp
;
import
java.io.IOException
;
import
jcl.data.mask.Mask
;
import
jcl.utils.Images.StreamedImageReaderWrapper
;