尝试纠正一组"无序像素",在先前使用Array插入的XML文件中列出(x assis上的列数,检测器数量失败)在TIF图像中使用插值( x-1)和(x +失败的探测器数量)/ 2。 在输入中,我有一个Tif图像,作为单层(PAN,MS1,MS2,MS3,MS4)和数组。在输出中我想要更正新图像。 我在setRGB中遇到了问题:
new_img.setRGB =((row + numOfDetectors)+(row - 1)/ 2);
和IOException e,在:
} catch(IOException e){
抱歉,我是Java语言的新手。谢谢..
class ArrayInterpolatorNew {
public static void main(String[] args) {
String path = "E:/IES_Interpol/Resources/Images/ByPass_PAN_C.tif";
String path1 = "E:/IES_Interpol/Resources/Images/ByPass_PAN_C_interpol.tif";
BufferedImage old_img = null;
try { old_img = ImageIO.read(new File(path));}
catch (Exception e) { e.printStackTrace(); }
// Developer may get all the pixels
int width = old_img.getWidth(null);
int height = old_img.getHeight(null);
BufferedImage new_img = new BufferedImage( old_img.getWidth(),
old_img.getHeight(),
BufferedImage.TYPE_BYTE_GRAY);
Graphics gr = new_img.getGraphics();
gr.drawImage(old_img, 0, 0, null);
gr.dispose();
try {
File file = new File("Resources/Images/ByPass_PAN_C_interpol.tif"); // The file to save to.
String format = "TIF"; // Example: "PNG" or "JPG"
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
ImageIO.write(new_img, "TIF", new File(path1));
//}
//catch (IOException e) { e.printStackTrace(); }
byte pix[] = new byte[1];
int n = new_img.getWidth();
int m = new_img.getHeight();
final int firstRow = 1;
final int numOfDetectors = 1;
//int row = image1.getWidth();
//int col = image1.getHeight();
double[][] matrix = new double[n][m];
double[][] Array = new double[firstRow][numOfDetectors];
//swips the rows
for (int row = 0; row < n; ++row)
{
//swips the columns
for (int col = 0; col < m; ++col)
{
//matrix[row][col] = new_img.getRGB(row, col);
new_img.getRaster().getDataElements(row, col, pix);
matrix[row][col] = pix[0];
}
for(int J = 0; J < firstRow; J++)
{
//if (row != J){
// set a pixel
//int image = image1.getRGB( row, col, pixelValue );
//image.setRGB(x, y, pixelValue);
if (row == J){
System.out.println("x,y: " + row + ", " + J + "num of Detectors: " + numOfDetectors);
new_img.setRGB = ((row + numOfDetectors) + (row - 1)/ 2);
if (row == J && numOfDetectors > 20){
System.out.println("x,y: " + row + ", " + J + "num of Detectors: " + numOfDetectors + "then > 20");
//new_img.setRGB(x, y, pixelValue);
int col = new_img.getHeight();
new_img.getRaster().getDataElements(row, col, pix);
matrix[row][col] = pix[0];
}
}
}
try {
//ImageIO.write(new_img, format, file);
} catch (IOException e) {
e.printStackTrace();
} finally { System.out.println("Images were written succesfully.");}
System.out.println("rest of the code...");
}
} finally {
}
}
}