create a duplicate of an image where the fit function is applied to the pixel values
()
| 172 | |
| 173 | /** create a duplicate of an image where the fit function is applied to the pixel values */ |
| 174 | void applyFunction() { |
| 175 | if (cf==null || fitType < 0) { |
| 176 | IJ.error("No function available"); |
| 177 | return; |
| 178 | } |
| 179 | ImagePlus img = WindowManager.getCurrentImage(); |
| 180 | if (img==null) { |
| 181 | IJ.noImage(); |
| 182 | return; |
| 183 | } |
| 184 | if (img.getTitle().matches("y\\s=.*")) { //title looks like a fit function |
| 185 | IJ.error("First select the image to be transformed"); |
| 186 | return; |
| 187 | } |
| 188 | double[] p = cf.getParams(); |
| 189 | int width = img.getWidth(); |
| 190 | int height = img.getHeight(); |
| 191 | int size = width*height; |
| 192 | float[] data = new float[size]; |
| 193 | ImageProcessor ip = img.getProcessor(); |
| 194 | float value; |
| 195 | for (int y=0; y<height; y++) { |
| 196 | for (int x=0; x<width; x++) { |
| 197 | value = ip.getPixelValue(x,y); |
| 198 | data[y*width+x] = (float)cf.f(p, value); |
| 199 | } |
| 200 | } |
| 201 | ImageProcessor ip2 = new FloatProcessor(width, height, data, ip.getColorModel()); |
| 202 | new ImagePlus(img.getTitle()+"-transformed", ip2).show(); |
| 203 | } |
| 204 | |
| 205 | void open() { |
| 206 | OpenDialog od = new OpenDialog("Open Text File...", ""); |
no test coverage detected