Переделай код, чтобы я вводи порог от 0 до 255. // Гистограмма для sawtooth4Image()…
- User
Переделай код, чтобы я вводи порог от 0 до 255. // Гистограмма для sawtooth4Image() private void zigzagContrastImage() { if (image != null) { // Запрос значений порогов у пользователя float t1 = userInput("Введите значение порога 1: ", 0, 255); float t2 = userInput("Введите значение порога 2: ", 0, 255);
// Проверка правильности введенных значений порогов if (t2 <= t1) { JOptionPane.showMessageDialog(null,“Значение порога 2 должно быть больше порога 1”); return; }
BufferedImage zigzagContrastImage1 = zigzagContrast(image, t1, t2, 0); setImageIcon(zigzagContrastImage1); saveImage(zigzagContrastImage1);
BufferedImage zigzagContrastImage2 = zigzagContrast(image, t1, t2, 1); setImageIcon(zigzagContrastImage2); saveImage(zigzagContrastImage2);
BufferedImage zigzagContrastImage3 = zigzagContrast(image, t1, t2, 2); setImageIcon(zigzagContrastImage3); saveImage(zigzagContrastImage3);
BufferedImage combinedImage = combineImages(zigzagContrastImage1, zigzagContrastImage2, zigzagContrastImage3); setImageIcon(combinedImage); saveImage(combinedImage);
int[] originalHistogram = ImageReader.getImageHistogram(image); int[] zigzagHistogram = ImageReader.getImageHistogram(combinedImage);
JFrame histogramFrame = new JFrame(“Гистограммы”); histogramFrame.setLayout(new GridLayout(1, 2, 10, 10));
JPanel originalHistogramPanel = ImageReader.createHistogramPanel(originalHistogram, “Гистограмма исходного изображения”);
JPanel zigzagHistogramPanel = ImageReader.createHistogramPanel(zigzagHistogram, “Гистограмма после контрастирования”);
histogramFrame.add(originalHistogramPanel); histogramFrame.add(zigzagHistogramPanel); histogramFrame.pack(); histogramFrame.setLocationRelativeTo(null); histogramFrame.setVisible(true); } }
private BufferedImage zigzagContrast(BufferedImage image, float t1, float t2, int direction) { BufferedImage resultImage = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_RGB); Color c;
int width = image.getWidth(); int height = image.getHeight();
// Define zigzag pattern for each row or column int[] zigzag = new int[width]; if (direction == 0) { for (int i = 0; i < width; i++) { zigzag[i] = i % (height * 2 - 2); if (zigzag[i] >= height) { zigzag[i] = (height - 2) - (zigzag[i] - height); } } } else if (direction == 1) { for (int i = 0; i < width; i++) { zigzag[i] = height - i % (height * 2 - 2) - 1; if (zigzag[i] < 0) { zigzag[i] = -zigzag[i] - 2; } } } else { for (int i = 0; i < height; i++) { zigzag[i] = i % (width * 2 - 2); if (zigzag[i] >= width) { zigzag[i] = (width - 2) - (zigzag[i] - width); } } }
for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { c = new Color(image.getRGB(x, y)); float brightness = (float) (0.299 * c.getRed() + 0.587 * c.getGreen() + 0.114 * c.getBlue()) / 255;
if (brightness < t1) { resultImage.setRGB(x, y, new Color(0, 0, 0).getRGB()); } else if (brightness >= t1 && brightness < t2) { float low = (brightness - t1) / (t2 - t1); float high = 1 - low; int value = (int) (zigzag[x] * low + (height - zigzag[x]) * high); c = new Color(value, value, value); resultImage.setRGB(x, y, c.getRGB()); } else { resultImage.setRGB(x, y, new Color(255, 255, 255).getRGB()); } } }
- Assistant
- User
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.