public static BufferedImage pinching(Image img) {
		BufferedImage bufImg = convert(img);
		BufferedImage resultImg = new BufferedImage(bufImg.getWidth(),
				bufImg.getHeight(), BufferedImage.TYPE_INT_RGB);

		int height = bufImg.getHeight();
		int width = bufImg.getWidth();

		int midX = width / 2;
		int midY = height / 2;

		int ynew = 0;
		for (int j = 0; j < height; j++) {
			int trueY = ynew - midY;
			int xnew = 0;
			for (int i = 0; i < width; i++) {
				int trueX = xnew - midX;
				double theta = Math.atan2(trueY, trueX);
				double radius = Math.sqrt(trueX * trueX + trueY * trueY);

				double newRadius = radius * radius / Math.max(midX, midY);
				int x = midX + (int) (newRadius * Math.cos(theta));
				int y = midY + (int) (newRadius * Math.sin(theta));

				/*
				 * for debugging only if(xnew==195&&ynew==250)
				 * System.out.println
				 * ("theta: "+theta+"\nradius: "+radius+"\nnewRadius: "
				 * +newRadius+"\nx: "+x+"    y: "+y+"\n newxy: "+xnew+" "+ynew);
				 * 
				 * //put the colout of x,y pixel from the original image to the
				 * xnew,ynew pixel of the buffered image if(x<0)
				 * do{x++;}while(x<0); if(x>bufImg.getWidth())
				 * do{x--;}while(x>bufImg.getWidth()); if(y<0)
				 * do{y++;}while(y<0); if(y>bufImg.getHeight())
				 * do{y--;}while(y>bufImg.getHeight());
				 */

				if (x >= 0 && y >= 0 && x < width && y < height) {
					int values = bufImg.getRGB(x, y);
					Color color = new Color(values);
					resultImg.setRGB(xnew, ynew, color.getRGB());
				} else {
					int values = bufImg.getRGB(i, j);
					Color color = new Color(values);
					bufImg.setRGB(xnew, ynew, color.getRGB());
					// Color newColor = new Color(0, 0, 255); //for debugging
					// resultImg.setRGB(xnew, ynew, newColor.getRGB());//for
					// debugging
				}
				xnew++;
			}
			ynew++;
		}
		return resultImg;
	}