如何从一个图像加载到另一个图像中的像素

时间:2019-01-22 13:17:03

标签: java imagej

我是Java和ImageJ的新手,我正在尝试使用ImageJ和Java编写PluginFilter。我希望它裁剪图像的左右两侧(每个500像素),将这些部分向外部旋转90度,然后将它们加载到新图像中。

我已经尝试了几种选择,但现在我完全感到困惑。我不认为算法本身有任何错误,但是在ImageProcessor等的处理方面。

import ij.*;
import ij.process.*;
import ij.gui.*;
import java.awt.*;
import ij.plugin.filter.*;

public class Cropping28_Plugin implements PlugInFilter {
    ImagePlus imp;
    public int setup(String arg, ImagePlus imp){
        imp = IJ.getImage();    
        this.imp = imp;
            return DOES_ALL;
}
    public void run(ImageProcessor ip){
          //  int[] p = null;
          // int[] q = null;
            int height = imp.getHeight();
        int width = imp.getWidth();
             // New Image
          ImagePlus new_image = IJ.createImage("Nr1", "RGB", height, 500, 1); 

// turning the picture for y=0:500 (left side of picture)
            for(int x = 0; x < height; x++){
                for(int y = 0; y < 500; y++){
                    int k = 0;
// loading pixel
                    int q = imp.getProcessor().getPixel(x, y);
                    int [] convert = {q, q, q};
// pixel in newimage
                    int a = height - k;
                    int b = x;
                    new_image.getProcessor().putPixel(a, b, convert);
                    k++;

}
}
// turning the picture for y=get.Length:get.Length-500 (right side of picture)
            for(int x = 0; x < height; x++){
                for(int y = width -500; y < width; y++){
                    int k = 0;
// loading pixel
                    int q = imp.getProcessor().getPixel(x, y);
                    int [] convert = {q, q, q};
// pixel in new image
                    int a = height - k;
                    int b = x;
                    new_image.getProcessor().putPixel(a, b, convert);
                    k++;

}
}
// draw new picture
    new_image.show();
    }
}

我希望输出是包含原始图像左右边缘像素的图片。实际输出是我期望的大小的写入图像。 如果有人有一个主意,那就太棒了!

0 个答案:

没有答案