Hello everyone,
I have a question to consult you.I want to implement the function that
extracts the R(red) of a gray image,the G(green) of the second of a gray
image and the B(blue) of another gray image to produce a Pseudo-color image
and saves it as Geotiff.The codes segment1 I make as follow only can produce
Pseudo-color image and save it as Tiff.
But how to save it as Geotiff? I try my best some times as the Codes
segment2,all are return false.And I donot know the relationship of
"bufferimage's RGB" and "GridCoverage2D's colors".And it also can not return
the result I expected.Please give me some suggesion.Thank you very much!
Codes segment1:
f1 = new File("./././data/geotiffr.tiff");
f2 = new File("./././data/geotiffg.tiff");
f3 = new File("./././data/geotiffb.tiff");
BufferedImage bufferedImage1 = null;
BufferedImage bufferedImage2 = null;
BufferedImage bufferedImage3 = null;
try {
bufferedImage1 = ImageIO.read(f1);
bufferedImage2 = ImageIO.read(f2);
bufferedImage3 = ImageIO.read(f3);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
BufferedImage bufferedImage=new BufferedImage(
bufferedImage1.getWidth(),
bufferedImage1.getHeight(),BufferedImage.TYPE_INT_RGB);
for (int y = 0; y < bufferedImage1.getHeight(); y++)
for (int x = 0; x < bufferedImage1.getWidth(); x++)
{
int rgb1= bufferedImage1.getRGB(x, y);
int rgb2= bufferedImage2.getRGB(x, y);
int rgb3= bufferedImage3.getRGB(x, y);
// System.out.println(rgb);
bufferedImage.setRGB(x, y, new Color( ((rgb1>>16 ) &
0xff) , ((rgb2 >>
8) & 0xff) ,((rgb3 ) & 0xff) ).getRGB());
}
Random random=new Random(System.currentTimeMillis());
String ext="tiff";
String filepath = "./././data/" + random.nextInt(99999) +
"." + ext;
try {
ImageIO.write(bufferedImage, ext, new
File(filepath));
System.out.println("tiff file has saved,the file path
is:" +
filepath);
}
catch (IOException ex) {
ex.printStackTrace();
}
Codes segment2:
.....
DataBuffer db1 = bufferedImage1.getData().getDataBuffer();
//bufferedImage1 is the same as above.
BufferedImage bufferedImage=new BufferedImage(
//bufferedImage is the result image
bufferedImage1.getWidth(),
bufferedImage1.getHeight(),BufferedImage.TYPE_INT_RGB);
Raster sourceraster3=bufferedImage.getData();
WritableRaster
raster=sourceraster1.createWritableRaster(sourceraster3.getSampleModel(),
db1,
sourceraster2.getBounds().getLocation());
GridCoverageFactory factory =
FactoryFinder.getGridCoverageFactory(null);
Color colors1[] = new
Color[bufferedImage1.getHeight()*bufferedImage1.getWidth()];
for (int y = 0; y < bufferedImage1.getHeight(); y++)
for (int x = 0; x < bufferedImage1.getWidth(); x++)
{
int rgb= bufferedImage1.getRGB(x, y);
int rgb1= bufferedImage1.getRGB(x, y);
int rgb2= bufferedImage2.getRGB(x, y);
rgb2=rgb2/2;
rgb1=rgb1/2;
colors1[y* bufferedImage1.getWidth()+x]= new
Color(((rgb1 >> 16) & 0xff)
, ((rgb2 >> 8) & 0xff) ,((rgb1 >> 16) & 0xff) ) ;
}
GridCoverage2D gc = factory.create("My colored coverage",
raster, envelope,
null, null, null, new Color[][] {colors1}, null);
.......
//Then call the geotiffwriter writer the
GridCoverage2D-----gc
--
View this message in context:
http://www.nabble.com/Can-geotools-write-Pseudo-color-image-as-ImageIO.write--tf4841875.html#a13852682
Sent from the geotools-gt2-users mailing list archive at Nabble.com.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users