51,410
社区成员
发帖
与我相关
我的任务
分享

for(int row=0; row<height; row++)
{
for(int col=0; col<width; col++)
{
double d = Math.sqrt((row - iniRow)*(row - iniRow) + (col - iniCol)*(col - iniCol));
double theta0 = Math.atan2(row - iniRow, col - iniCol);
double ds = d + (double)waveValue * 0.01 * Math.min(height, width) * Math.sin(0.1 * d * frequency);import java.awt.*;
import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.border.EtchedBorder;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import java.awt.event.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
public class ImageStaticProcessorPanel extends JPanel implements ActionListener ,ItemListener
{
//inner processor
private static final long serialVersionUID = 1L;
private WaveGenerator waveGenerator;
//system parameters
private ImageIcon sample;
private Image tempImage;
private BufferedImage inImage, outImage;
private int filterType;
private int interpolationType;
private GridBagConstraints c;
private final int INTERPOLATION_INT_NEAR = 0, INTERPOLATION_INT_BILINEAR = 1, INTERPOLATION_INT_BICUBIC = 2;
private final int FILTER_INT_WAVE = 0, FILTER_INT_TWIST = 1;
private File f;
//components
private JButton startButton, reverseButton, magnifierButton;
private JLabel imageLabel;
private JComboBox interpolationJComboBox, filterJComboBox;
private SliderPanel sliderPanel;
//Constructor
public ImageStaticProcessorPanel()
{
setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
//default image
sample = new ImageIcon("d:/test2.jpg");
tempImage = sample.getImage();
f = new File("d:/test1.jpg");
try{
inImage = ImageIO.read(new FileInputStream("d:/test2.jpg"));
//ImageIO.write(inImage, "jpg", f);
}catch(IOException e){
e.printStackTrace();
}
imageLabel = new JLabel(sample);
add(imageLabel);
//bigPanel
JPanel bigPanel = new JPanel();
bigPanel.setLayout(new BoxLayout(bigPanel, BoxLayout.Y_AXIS));
//ctrlPanel
JPanel ctrlPanel = new JPanel();
ctrlPanel.setLayout(new GridBagLayout());
c = new GridBagConstraints();
Border ctrlBorder = BorderFactory.createEtchedBorder(EtchedBorder.LOWERED);
ctrlPanel.setBorder(BorderFactory.createTitledBorder(ctrlBorder, "Items"));;
String[] filters = {"Wave ", "Twist "};
filterJComboBox = new JComboBox(filters);
c = setupConstraints(0, 0, 5, 2, GridBagConstraints.NORTH);
ctrlPanel.add(filterJComboBox, c);
this.filterJComboBox.addItemListener(this);
this.filterType = FILTER_INT_WAVE;
//
String[] interpolations = {"Nearest ", "Bilinear ", "Bicubic "};
interpolationJComboBox = new JComboBox(interpolations);
c = setupConstraints(0, 2, 5, 2, GridBagConstraints.NORTH);
ctrlPanel.add(interpolationJComboBox, c);
this.interpolationJComboBox.addItemListener(this);
this.interpolationType = this.INTERPOLATION_INT_NEAR;
this.startButton = new JButton(" Start ");
//startButton.setSize(3, 2);
c = setupConstraints(0, 4, 3, 2, GridBagConstraints.NORTH);
ctrlPanel.add(startButton, c);
this.startButton.addActionListener(this);
//
this.reverseButton = new JButton(" Reverse ");
c = setupConstraints(5, 4, 3, 2, GridBagConstraints.NORTH);
ctrlPanel.add(reverseButton, c);
this.reverseButton.addActionListener(this);
//
this.magnifierButton = new JButton(" Magnifier ");
c = setupConstraints(0, 6, 3, 2, GridBagConstraints.NORTH);
ctrlPanel.add(magnifierButton, c);
this.magnifierButton.addActionListener(this);
bigPanel.add(ctrlPanel);
//slider panel
sliderPanel = new SliderPanel("wave");
bigPanel.add(sliderPanel);
JPanel blankPanel = new JPanel();
bigPanel.add(blankPanel);
add(bigPanel);
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
Object source = e.getSource();
if(source == this.startButton)
{
waveGenerator = new WaveGenerator();
waveGenerator.setWaveValue(sliderPanel.getPara1());
waveGenerator.setFrequency(sliderPanel.getPara2());
outImage = waveGenerator.filter(inImage, outImage, inImage.getHeight()/2, inImage.getWidth()/2, interpolationType, filterType);
sample.setImage(outImage);
imageLabel.setIcon(sample);
imageLabel.repaint();
try{
ImageIO.write(outImage, "jpg", f);
}catch(IOException e1){
e1.printStackTrace();
}
}
}
@Override
public void itemStateChanged(ItemEvent e) {
// TODO Auto-generated method stub
Object source = e.getSource();
if(source == this.filterJComboBox)
{
if(e.getItem() == "Wave " && e.getStateChange() == ItemEvent.SELECTED)
this.filterType = this.FILTER_INT_WAVE;
else if(e.getItem() == "Twist " && e.getStateChange() == ItemEvent.SELECTED)
this.filterType = this.FILTER_INT_TWIST;
}
else if(source == this.interpolationJComboBox)
{
if(e.getItem() == "Nearest " && e.getStateChange() == ItemEvent.SELECTED)
this.interpolationType = this.INTERPOLATION_INT_NEAR;
else if(e.getItem() == "Bilinear " && e.getStateChange() == ItemEvent.SELECTED)
this.interpolationType = this.INTERPOLATION_INT_BILINEAR;
else if(e.getItem() == "Bicubic " && e.getStateChange() == ItemEvent.SELECTED)
this.interpolationType = this.INTERPOLATION_INT_BICUBIC;
}
}
//
private GridBagConstraints setupConstraints(int gridx, int gridy, int gridwidth, int gridheight, int anchor)
{
GridBagConstraints c = new GridBagConstraints();
c.gridx = gridx;
c.gridy = gridy;
c.gridwidth = gridwidth;
c.gridheight = gridheight;
c.ipadx = c.ipady = 0;
c.insets = new Insets(5,5,5,5);
c.anchor = anchor;
return c;
}
}
主Frame:
import java.awt.*;
import javax.swing.*;
import javax.swing.event.MenuEvent;
import javax.swing.event.MenuListener;
public class ImageProcessorFrame extends JFrame implements MenuListener{
private ImageStaticProcessorPanel staticPanel;
//constructor
public ImageProcessorFrame()
{
setTitle("FilterMaster");
setSize(800, 500);
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
this.staticPanel = new ImageStaticProcessorPanel();
this.add(this.staticPanel);
}
/*
*
* (non-Javadoc)
* @see javax.swing.event.MenuListener#menuSelected(javax.swing.event.MenuEvent)
*/
@Override
public void menuSelected(MenuEvent e) {
// TODO Auto-generated method stub
}
@Override
public void menuDeselected(MenuEvent e) {
// TODO Auto-generated method stub
}
@Override
public void menuCanceled(MenuEvent e) {
// TODO Auto-generated method stub
}
}
滑块Panel:
import java.awt.*;
import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.border.EtchedBorder;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
public class SliderPanel extends JPanel implements ChangeListener{
private double para1, para2;
private String name1, name2;
private Border selectedBorder1, selectedBorder2;
private JSlider slider1, slider2;
BoxLayout boxLayout;
public SliderPanel(String panelName)
{
boxLayout = new BoxLayout(this, BoxLayout.Y_AXIS);
if(panelName =="wave")
{
//ChangeListener wChangelistener = new ChangeListener();
this.selectedBorder1 = BorderFactory.createEtchedBorder(EtchedBorder.LOWERED);
slider1 = new JSlider(0, 50);
slider1.setMinorTickSpacing(1);
slider1.setMajorTickSpacing(5);
slider1.setPaintTicks(true);
slider1.setPaintLabels(true);
slider1.setBorder(BorderFactory.createTitledBorder(selectedBorder1, "Amplitude: " + 25));
slider1.addChangeListener(this);
this.selectedBorder2 = BorderFactory.createEtchedBorder(EtchedBorder.LOWERED);
slider2 = new JSlider(0, 150);
slider2.setMinorTickSpacing(1);
slider2.setMajorTickSpacing(20);
slider2.setPaintTicks(true);
slider2.setPaintLabels(true);
slider2.setBorder(BorderFactory.createTitledBorder(selectedBorder2, "Frequency: " + 120));
slider2.addChangeListener(this);
setLayout(boxLayout);
this.add(slider1);
this.add(slider2);
}
}
@Override
public void stateChanged(ChangeEvent e)
{
// TODO Auto-generated method stub
Object source = e.getSource();
if(source == slider1)
{
para1 = slider1.getValue();
slider1.setBorder(BorderFactory.createTitledBorder(selectedBorder1, "Amplitude: " + para1));
}
if(source == slider2)
{
para2 = slider2.getValue();
slider2.setBorder(BorderFactory.createTitledBorder(selectedBorder2, "Frequency: " + para2));
}
}
public double getPara1()
{
return para1;
}
public double getPara2()
{
return para2;
}
}
启动类:
public class ImageProcessApp {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
ImageProcessorFrame frame = new ImageProcessorFrame();
//frame.pack();
frame.setVisible(true);
frame.setResizable(false);
}
}

import java.awt.image.BufferedImage;
import java.awt.*;
import java.math.*;
import java.awt.Point;
public class WaveGenerator{
//parameters
private double waveValue;
private double frequency;
private final int INTERPOLATION_INT_NEAR = 0, INTERPOLATION_INT_BILINEAR = 1, INTERPOLATION_INT_BICUBIC = 2;
private final int FILTER_INT_WAVE = 0, FILTER_INT_TWIST = 1;
public WaveGenerator(){
this.waveValue = 5.0;
this.frequency = 5;
}
public void setWaveValue(double waveValue)
{
this.waveValue = waveValue;
}
public void setFrequency(double frequency)
{
this.frequency = frequency;
}
public BufferedImage filter(BufferedImage src, BufferedImage dest, int iniRow, int iniCol, int interpolationType, int filterType)
{
int width = src.getWidth();
int height = src.getHeight();
int[] inPixels = new int[width*height];
int[] outPixels = new int[width*height];
double[][] ssPixelx = new double[height][width];
double[][] ssPixely = new double[height][width];
src.getRGB(0, 0, width, height, inPixels, 0, width);
System.out.println(inPixels.length);
if(dest == null)
{
dest = new BufferedImage(src.getHeight(), src.getWidth(), src.getType());
System.out.println(dest.getHeight() + "*" + dest.getWidth());
//dest.setRGB(0, 0, width, height, inPixels, 0, width);
}
double xoffset = 0, yoffset = 0;
if(filterType == this.FILTER_INT_WAVE)
{
for(int row=0; row<height; row++)
{
for(int col=0; col<width; col++)
{
double d = Math.sqrt((row - iniRow)*(row - iniRow) + (col - iniCol)*(col - iniCol));
double theta0 = Math.atan2(row - iniRow, col - iniCol);
double ds = d + (double)waveValue * 0.01 * Math.min(height, width) * Math.sin(0.1 * d * frequency);
/*
xoffset = (double)waveValue * Math.sin(2.0 * Math.PI * d / period) * ((col - iniCol) / d) ; //what about d = 0
yoffset = (double)waveValue * Math.sin(2.0 * Math.PI * d / period) * ((row - iniRow) / d) ;
*/
xoffset = ds * Math.cos(theta0) + iniCol;
yoffset = ds * Math.sin(theta0) + iniRow;
if(xoffset < 0)
{
xoffset = 0;
}
else if(xoffset >= width)
{
xoffset = width-1;
}
if(yoffset < 0)
{
yoffset = 0;
}
else if(yoffset >= height)
{
yoffset = height - 1;
}
//save the newX and newY for interpolation of different type
ssPixelx[row][col] = xoffset;
ssPixely[row][col] = yoffset;
}
}
}
else if(filterType == this.FILTER_INT_TWIST)
{
}
else
{
}
Interpolationer interpolationer = new Interpolationer(width, height);
if(interpolationType == this.INTERPOLATION_INT_NEAR)
outPixels = interpolationer.nearNeighborInterpolation(ssPixelx, ssPixely, inPixels, width, height);
else if(interpolationType == this.INTERPOLATION_INT_BILINEAR)
outPixels = interpolationer.biLinearInterpolation(ssPixelx, ssPixely, inPixels, width, height);
else if(interpolationType == this.INTERPOLATION_INT_BICUBIC)
outPixels = interpolationer.biCubicInterpolation(ssPixelx, ssPixely, inPixels, width, height);
else
outPixels = inPixels;
//System.out.println(interpolationType);
System.out.println(inPixels.length);
System.out.println(outPixels.length);
System.out.println(dest.getWidth());
System.out.println(dest.getHeight());
for(int r=0; r<dest.getHeight(); r++)
{
for(int c=0; c<dest.getWidth(); c++)
{
dest.setRGB(c, r, outPixels[r*dest.getWidth()+c]);
}
}
//dest.setRGB(0, 0, width, height, outPixels, 0, width);
return dest;
}
import java.awt.image.BufferedImage;
import java.math.*;
public class Interpolationer {
//cubic parameters
private double a00, a01, a02, a03;
private double a10, a11, a12, a13;
private double a20, a21, a22, a23;
private double a30, a31, a32, a33;
private int width, height;
//Constructor
public Interpolationer(int width, int height)
{
this.width = width;
this.height = height;
}
//cubic
public int[] biCubicInterpolation(double[][] ssPixelx, double[][] ssPixely, int[] inPixels, int col, int row)
{
int[] outPixels = new int[inPixels.length];
int rInt, cInt;
double rDouble, cDouble;
int[][][] tempThreeIn = new int[row][col][4];
int[][][] tempThreeOut = new int[row][col][4];
double[][] relativePix = new double[4][4];
tempThreeIn = this.processOneToThreeDeminsion(inPixels, row, col);
for(int r=0; r<row; r++)
{
for(int c=0; c<col; c++)
{
rInt = (int)Math.floor(ssPixely[r][c]);
cInt = (int)Math.floor(ssPixelx[r][c]);
rDouble = ssPixely[r][c] - rInt;
cDouble = ssPixelx[r][c] - cInt;
for(int i=0; i<4; i++)
{
relativePix[0][0] = getRGBValue(tempThreeIn, rInt-1, cInt-1, i);
relativePix[0][1] = getRGBValue(tempThreeIn, rInt-1, cInt, i);
relativePix[0][2] = getRGBValue(tempThreeIn, rInt-1,cInt+1, i);
relativePix[0][3] = getRGBValue(tempThreeIn, rInt-1, cInt+2,i);
relativePix[1][0] = getRGBValue(tempThreeIn, rInt, cInt-1, i);
relativePix[1][1] = getRGBValue(tempThreeIn, rInt, cInt, i);
relativePix[1][2] = getRGBValue(tempThreeIn, rInt, cInt+1, i);
relativePix[1][3] = getRGBValue(tempThreeIn, rInt, cInt+2, i);
relativePix[2][0] = getRGBValue(tempThreeIn, rInt+1,cInt-1,i);
relativePix[2][1] = getRGBValue(tempThreeIn, rInt+1, cInt, i);
relativePix[2][2] = getRGBValue(tempThreeIn, rInt+1, cInt+1, i);
relativePix[2][3] = getRGBValue(tempThreeIn, rInt+1, cInt+2, i);
relativePix[3][0] = getRGBValue(tempThreeIn, rInt+2, cInt-1, i);
relativePix[3][1] = getRGBValue(tempThreeIn, rInt+2, cInt, i);
relativePix[3][2] = getRGBValue(tempThreeIn, rInt+2, cInt+1, i);
relativePix[3][3] = getRGBValue(tempThreeIn, rInt+2, cInt+2, i);
this.updateCoefficients(relativePix);
tempThreeOut[r][c][i] = (int)getValue(rDouble, cDouble);
}
}
}
outPixels = this.processThreeToOneDim(tempThreeOut, row, col);
return outPixels;
}
//linear
public int[] biLinearInterpolation(double[][] ssPixelx, double[][] ssPixely, int[] inPixels, int col, int row)
{
int[] outPixels = new int[inPixels.length];
//linear parameters
int rInt, cInt;
double rDouble, cDouble;
double cofficient1, cofficient2, cofficient3, cofficient4;
//
int[][][] tempThreeIn = new int[row][col][4];
int[][][] tempThreeOut = new int[row][col][4];
tempThreeIn = this.processOneToThreeDeminsion(inPixels, row, col);
for(int r=0; r<row; r++)
{
for(int c=0; c<col; c++)
{
rInt = (int)Math.floor(ssPixely[r][c]);
cInt = (int)Math.floor(ssPixelx[r][c]);
rDouble = ssPixely[r][c] - rInt;
cDouble = ssPixelx[r][c] - cInt;
cofficient1 = (1.0d - rDouble) * (1.0d - cDouble);
cofficient2 = (rDouble) * (1.0d - cDouble);
cofficient3 = cDouble * rDouble;
cofficient4 = (1.0d - rDouble) * cDouble;
int rInt1 = rInt + 1;
int cInt1 = cInt + 1;
int rInt0 = rInt;
int cInt0 = cInt;
if(rInt1 >= row)
rInt1 = row - 1;
if(rInt0 >= row)
rInt0 = row - 1;
if(cInt1 >= col)
cInt1 = col - 1;
if(cInt0 >= col)
cInt0 = col - 1;
tempThreeOut[r][c][0] = (int)(cofficient1 * tempThreeIn[rInt0][cInt0][0]
+ cofficient2 * tempThreeIn[rInt1][cInt0][0]
+ cofficient3 * tempThreeIn[rInt0][cInt1][0]
+ cofficient4 * tempThreeIn[rInt1][cInt1][0]);
tempThreeOut[r][c][0] = (int)(cofficient1 * tempThreeIn[rInt0][cInt0][1]
+ cofficient2 * tempThreeIn[rInt1][cInt0][1]
+ cofficient3 * tempThreeIn[rInt0][cInt1][1]
+ cofficient4 * tempThreeIn[rInt1][cInt1][1]);
tempThreeOut[r][c][0] = (int)(cofficient1 * tempThreeIn[rInt0][cInt0][2]
+ cofficient2 * tempThreeIn[rInt1][cInt0][2]
+ cofficient3 * tempThreeIn[rInt0][cInt1][2]
+ cofficient4 * tempThreeIn[rInt1][cInt1][2]);
tempThreeOut[r][c][0] = (int)(cofficient1 * tempThreeIn[rInt0][cInt0][3]
+ cofficient2 * tempThreeIn[rInt1][cInt0][3]
+ cofficient3 * tempThreeIn[rInt0][cInt1][3]
+ cofficient4 * tempThreeIn[rInt1][cInt1][3]);
}
}
outPixels = this.processThreeToOneDim(tempThreeOut, row, col);
return outPixels;
}
//near neighbor
public int[] nearNeighborInterpolation(double[][] ssPixelx, double[][] ssPixely, int[] inPixels, int col, int row)
{
int[] outPixels = new int[inPixels.length];
int rConverted, cConverted;
int[][][] tempThreeIn = new int[row][col][4];
int[][][] tempThreeOut = new int[row][col][4];
tempThreeIn = this.processOneToThreeDeminsion(inPixels, row, col);
//to fill the tempThreeOut with nearest source value
for(int r=0; r<row; r++)
{
for(int c=0; c<col; c++)
{
//find nearest point via round
rConverted = (int)Math.round(ssPixely[r][c]);
cConverted = (int)Math.round(ssPixelx[r][c]);
if(rConverted >= row)
rConverted = row - 1;
if(cConverted >= col)
cConverted = col - 1;
tempThreeOut[r][c][0] = tempThreeIn[rConverted][cConverted][0];
tempThreeOut[r][c][1] = tempThreeIn[rConverted][cConverted][1];
tempThreeOut[r][c][2] = tempThreeIn[rConverted][cConverted][2];
tempThreeOut[r][c][3] = tempThreeIn[rConverted][cConverted][3];
}
}
outPixels = this.processThreeToOneDim(tempThreeOut, row, col);
return outPixels;
}
//method for dimension transformation
public int[] processThreeToOneDim(int[][][] inThreeDPix, int imgRows, int imgCols)
{
int[] oneDPix = new int[imgCols * imgRows];
for (int row = 0, cnt = 0; row < imgRows; row++)
{
for (int col = 0; col < imgCols; col++)
{
oneDPix[cnt] = ((inThreeDPix[row][col][0] << 24) & 0xFF000000)
| ((inThreeDPix[row][col][1] << 16) & 0x00FF0000)
| ((inThreeDPix[row][col][2] << 8) & 0x0000FF00)
| ((inThreeDPix[row][col][3]) & 0x000000FF);
cnt++;
}
}
return oneDPix;
}
public int[][][] processOneToThreeDeminsion(int[] inOneDPix, int imgRows, int imgCols)
{
int[][][] threeDPix = new int[imgRows][imgCols][4];
for(int row=0; row<imgRows; row++)
{
int[] aRow = new int[imgCols];
for(int col=0; col<imgCols; col++)
{
int num = row * imgCols +col;
aRow[col] = inOneDPix[num];
}
for(int col=0; col<imgCols; col++)
{
threeDPix[row][col][0] = (aRow[col] >> 24 ) & 0xff; //alpha
threeDPix[row][col][1] = (aRow[col] >> 16 ) & 0xff; //alpha
threeDPix[row][col][2] = (aRow[col] >> 8 ) & 0xff; //alpha
threeDPix[row][col][3] = (aRow[col] ) & 0xff; //alpha
}
}
return threeDPix;
}
//sub-method for double cubic interpolation
public double getValue(double x, double y)
{
double x2 = x * x;
double x3 = x * x2;
double y2 = y * y;
double y3 = y * y2;
return (a00 + a01 * y + a02 * y2 + a03 * y3) +
(a10 + a11 * y + a12 * y2 + a13 * y3) * x +
(a20 + a21 * y + a22 * y2 + a23 * y3) * x2 +
(a30 + a31 * y + a32 * y2 + a33 * y3) * x3;
}
public void updateCoefficients (double[][] p) {
a00 = p[1][1];
a01 = -.5*p[1][0] + .5*p[1][2];
a02 = p[1][0] - 2.5*p[1][1] + 2*p[1][2] - .5*p[1][3];
a03 = -.5*p[1][0] + 1.5*p[1][1] - 1.5*p[1][2] + .5*p[1][3];
a10 = -.5*p[0][1] + .5*p[2][1];
a11 = .25*p[0][0] - .25*p[0][2] - .25*p[2][0] + .25*p[2][2];
a12 = -.5*p[0][0] + 1.25*p[0][1] - p[0][2] + .25*p[0][3] + .5*p[2][0] - 1.25*p[2][1] + p[2][2] - .25*p[2][3];
a13 = .25*p[0][0] - .75*p[0][1] + .75*p[0][2] - .25*p[0][3] - .25*p[2][0] + .75*p[2][1] - .75*p[2][2] + .25*p[2][3];
a20 = p[0][1] - 2.5*p[1][1] + 2*p[2][1] - .5*p[3][1];
a21 = -.5*p[0][0] + .5*p[0][2] + 1.25*p[1][0] - 1.25*p[1][2] - p[2][0] + p[2][2] + .25*p[3][0] - .25*p[3][2];
a22 = p[0][0] - 2.5*p[0][1] + 2*p[0][2] - .5*p[0][3] - 2.5*p[1][0] + 6.25*p[1][1] - 5*p[1][2] + 1.25*p[1][3] + 2*p[2][0] - 5*p[2][1] + 4*p[2][2] - p[2][3] - .5*p[3][0] + 1.25*p[3][1] - p[3][2] + .25*p[3][3];
a23 = -.5*p[0][0] + 1.5*p[0][1] - 1.5*p[0][2] + .5*p[0][3] + 1.25*p[1][0] - 3.75*p[1][1] + 3.75*p[1][2] - 1.25*p[1][3] - p[2][0] + 3*p[2][1] - 3*p[2][2] + p[2][3] + .25*p[3][0] - .75*p[3][1] + .75*p[3][2] - .25*p[3][3];
a30 = -.5*p[0][1] + 1.5*p[1][1] - 1.5*p[2][1] + .5*p[3][1];
a31 = .25*p[0][0] - .25*p[0][2] - .75*p[1][0] + .75*p[1][2] + .75*p[2][0] - .75*p[2][2] - .25*p[3][0] + .25*p[3][2];
a32 = -.5*p[0][0] + 1.25*p[0][1] - p[0][2] + .25*p[0][3] + 1.5*p[1][0] - 3.75*p[1][1] + 3*p[1][2] - .75*p[1][3] - 1.5*p[2][0] + 3.75*p[2][1] - 3*p[2][2] + .75*p[2][3] + .5*p[3][0] - 1.25*p[3][1] + p[3][2] - .25*p[3][3];
a33 = .25*p[0][0] - .75*p[0][1] + .75*p[0][2] - .25*p[0][3] - .75*p[1][0] + 2.25*p[1][1] - 2.25*p[1][2] + .75*p[1][3] + .75*p[2][0] - 2.25*p[2][1] + 2.25*p[2][2] - .75*p[2][3] - .25*p[3][0] + .75*p[3][1] - .75*p[3][2] + .25*p[3][3];
}
public double getRGBValue(int[][][] inThreePix, int row, int col, int index)
{
if(col >= width)
col = width - 1;
if(col <0)
col = 0;
if(row >= height)
row = height - 1;
if(row <0)
row = 0;
return inThreePix[(int)row][(int)col][index];
}
}
有三种插值方法,我用临近插值就出现问题了。
并且当我水波公式里waveValue = 0,frequency = 0时,图像应该不变。。不知何解