gpt-3.5-turbo-0301· openai
from WildChat-4.8M
Fix the code. } private void brightnessImage() { if (image != null) { int…
- User
Fix the code. } private void brightnessImage() { if (image != null) { int minBrightness=50; int maxBrightness=50; // устанавливаем значение по умолчанию
code// Создаем панель для пороговых значений JPanel thresholdPanel = new JPanel(new GridLayout(1, 2)); // Создаем текстовое поле для порога JTextField thresholdField = new JTextField(Integer.toString(threshold)); thresholdPanel.add(new JLabel("Порог: ")); thresholdPanel.add(thresholdField); // Создаем окно для ввода пороговых значений int result = JOptionPane.showConfirmDialog(null, thresholdPanel, "Введите пороговое значение", JOptionPane.OK_CANCEL_OPTION); if (result == JOptionPane.OK_OPTION) { // Обновляем порог threshold = Integer.parseInt(thresholdField.getText()); BufferedImage binarizedImage = binarizeImage(image, threshold); if (brightnessSliceImage != null) { // ИЗМЕНЕНИЕ: передаем в метод setImageIcon() бинаризованное изображение setImageIcon(brightnessSliceImage); saveImage(brightnessSliceImage); // Создаем гистограмму исходного изображения int[] histogram = new int[256]; for (int i = 0; i < image.getWidth(); i++) { for (int j = 0; j < image.getHeight(); 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); histogram[brightness]++; } } // Создаем гистограмму преобразованного изображения int[] brightnessSliceHistogram = new int[256]; for (int i = 0; i < brightnessSliceImage.getWidth(); i++) { for (int j = 0; j < brightnessSliceImage.getHeight(); j++) { int pixel = brightnessSliceImage.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); brightnessSliceHistogram[brightness]++; } } - Assistant
} private void brightnessImage() { if (image != null) { int threshold=50; // устанавливаем значение по умолчанию
code