Fix the code. // Функция пилообразного контрастирования с порогами и направлением вниз…
- User
Fix the code. // Функция пилообразного контрастирования с порогами и направлением вниз private BufferedImage sawtoothContrastDown(BufferedImage image, float t1, float t2) { BufferedImage output = new BufferedImage(image.getWidth(), image.getHeight(), image.getType()); for (int i = 0; i < image.getWidth(); i++) { for (int j = image.getHeight()-1; j >= 0; j–) { // изменен порядок обхода по y int pixel = image.getRGB(i, j); int red = (pixel >> 16) & 0xff; int green = (pixel >> 8) & 0xff; int blue = pixel & 0xff; int brightness = (int) (0.2126 * red + 0.7152 * green + 0.0722 * blue); if (brightness < t1) { output.setRGB(i, j, new Color(255, 255, 255).getRGB()); } else if (brightness >= t1 && brightness < t2) { int value = (int) (255 - 255 * (brightness - t1) / (t2 - t1)); output.setRGB(i, j, new Color(value, value, value).getRGB()); } else if (brightness >= t2) { output.setRGB(i, j, new Color(0, 0, 0).getRGB()); } } } return output; }
- Assistant
// Fixed code: private BufferedImage sawtoothContrastDown(BufferedImage image, float t1, float t2) { BufferedImage output = new BufferedImage(image.getWidth(), image.getHeight(), image.getType()); for (int i = 0; i < image.getWidth(); i++) { for (int j = image.getHeight() - 1; j >= 0; j--) { int pixel = image.getRGB(i, j); int red = (pixel >> 16) & 0xff; int green = (pixel >> 8) & 0xff; int blue = pixel & 0xff; int brightness = (int) (0.2126 * red + 0.7152 * green + 0.0722 * blue); if (brightness < t1) { output.setRGB(i, j, new Color(255, 255, 255).getRGB()); } else if (brightness >= t1 && brightness < t2) { int value = (int) (255 - 255 * (brightness - t1) / (t2 - t1)); output.setRGB(i, j, new Color(value, value, value).getRGB()); } else if (brightness >= t2) { output.setRGB(i, j, new Color(0, 0, 0).getRGB()); } } } return output; }
- User
j– invalid character. fix this. private BufferedImage sawtoothContrastDown(BufferedImage image, float t1, float t2) { BufferedImage output = new BufferedImage(image.getWidth(), image.getHeight(), image.getType()); for (int i = 0; i < image.getWidth(); i++) { for (int j = image.getHeight() - 1; j >= 0; j–) { int pixel = image.getRGB(i, j); int red = (pixel >> 16) & 0xff; int green = (pixel >> 8) & 0xff; int blue = pixel & 0xff; int brightness = (int) (0.2126 * red + 0.7152 * green + 0.0722 * blue); if (brightness < t1) { output.setRGB(i, j, new Color(255, 255, 255).getRGB()); } else if (brightness >= t1 && brightness < t2) { int value = (int) (255 - 255 * (brightness - t1) / (t2 - t1)); output.setRGB(i, j, new Color(value, value, value).getRGB()); } else if (brightness >= t2) { output.setRGB(i, j, new Color(0, 0, 0).getRGB()); } } } return output; }
- Assistant
Fixed code: private BufferedImage sawtoothContrastDown(BufferedImage image, float t1, float t2) { BufferedImage output = new BufferedImage(image.getWidth(), image.getHeight(), image.getType()); for (int i = 0; i < image.getWidth(); i++) { for (int j = image.getHeight() - 1; j >= 0; j--) { int pixel = image.getRGB(i, j); int red = (pixel >> 16) & 0xff; int green = (pixel >> 8) & 0xff; int blue = pixel & 0xff; int brightness = (int) (0.2126 * red + 0.7152 * green + 0.0722 * blue); if (brightness < t1) { output.setRGB(i, j, new Color(255, 255, 255).getRGB()); } else if (brightness >= t1 && brightness < t2) { int value = (int) (255 - 255 * (brightness - t1) / (t2 - t1)); output.setRGB(i, j, new Color(value, value, value).getRGB()); } else if (brightness >= t2) { output.setRGB(i, j, new Color(0, 0, 0).getRGB()); } } } return output; }
- User
- Assistant