Переделай код пилообразное контрастирование с тремя пилами. // Гистограмма для…
- User
Переделай код пилообразное контрастирование с тремя пилами. // Гистограмма для sawtooth4Image() private void sawtooth4Image() { boolean valid = true; // Убираем переменную valid из условия, чтобы ее значение сохранялось между вызовами метода while (valid) { // Используем цикл, чтобы можно было изменять изображение несколько раз if (image != null) { // Запрос значения порогов в цикле до тех пор, пока пользователь не введет правильные значения float t1 = userInput("Введите значение порога 1: ", 0, 1); float t2 = userInput("Введите значение порога 2: ", 0, 1); if (t2 > t1) { BufferedImage sawtoothContrastImage1 = sawtoothContrastUp(image, t1, t2); BufferedImage sawtoothContrastImage2 = sawtoothContrastDown(image, t1, t2); BufferedImage combinedImage = combineImages(sawtoothContrastImage1, sawtoothContrastImage2, sawtoothContrastImage1);
setImageIcon(combinedImage); saveImage(combinedImage);
int[] originalHistogram = ImageReader.getImageHistogram(image); int[] sawtoothHistogram = ImageReader.getImageHistogram(combinedImage);
JFrame histogramFrame = new JFrame(“Гистограммы”); histogramFrame.setLayout(new GridLayout(1, 2, 10, 10));
JPanel originalHistogramPanel = ImageReader.createHistogramPanel(originalHistogram, “Гистограмма исходного изображения”);
JPanel sawtoothHistogramPanel = ImageReader.createHistogramPanel(sawtoothHistogram, “Гистограмма после контрастирования”);
histogramFrame.add(originalHistogramPanel); histogramFrame.add(sawtoothHistogramPanel); histogramFrame.pack(); histogramFrame.setLocationRelativeTo(null); histogramFrame.setVisible(true);
image = combinedImage; // Сохраняем измененное изображение в переменную image
// Запрос новых значений порогов } else { JOptionPane.showMessageDialog(null, “Значение порога 2 должно быть больше порога 1”); } } else { valid = false; } } }
- Assistant
private void sawtooth4Image() { boolean valid = true; while (valid) { if (image != null) { float t1 = userInput("Введите значение порога 1: ", 0, 1); float t2 = userInput("Введите значение порога 2: ", 0, 1); if (t2 > t1) { BufferedImage sawtoothContrastImage1 = sawtoothContrastUp(image, t1, t2); BufferedImage sawtoothContrastImage2 = sawtoothContrastDown(image, t1, t2); BufferedImage sawtoothContrastImage3 = sawtoothContrastUp(image, 0, t1); BufferedImage combinedImage = combineImages(sawtoothContrastImage1, sawtoothContrastImage2, sawtoothContrastImage3, sawtoothContrastImage2, sawtoothContrastImage1);
code - User
The method combineImages(BufferedImage, BufferedImage, BufferedImage) in the type ImageReader is not applicable for the arguments (BufferedImage, BufferedImage, BufferedImage, BufferedImage, BufferedImage). Fix this. // Гистограмма для sawtooth4Image() private void sawtooth4Image() { boolean valid = true; while (valid) { if (image != null) { float t1 = userInput("Введите значение порога 1: ", 0, 1); float t2 = userInput("Введите значение порога 2: ", 0, 1); if (t2 > t1) { BufferedImage sawtoothContrastImage1 = sawtoothContrastUp(image, t1, t2); BufferedImage sawtoothContrastImage2 = sawtoothContrastDown(image, t1, t2); BufferedImage sawtoothContrastImage3 = sawtoothContrastUp(image, 0, t1); BufferedImage combinedImage = combineImages(sawtoothContrastImage1, sawtoothContrastImage2, sawtoothContrastImage3, sawtoothContrastImage2, sawtoothContrastImage1);
- Assistant
To fix this error, we need to modify the
combineImagesmethod in theImageReaderclass to accept fiveBufferedImagearguments instead of three, since we're now passing five arguments insawtooth4Image()method.Modify the signature of the
combineImagesmethod inImageReaderclass as follows:codepublic static BufferedImage combineImages(BufferedImage image1, BufferedImage image2, BufferedImage image3, BufferedImage image4, BufferedImage image5)Then, update the method call inside
sawtooth4Image()to pass all five images as arguments:codeBufferedImage combinedImage = combineImages(sawtoothContrastImage1, sawtoothContrastImage2, sawtoothContrastImage3, sawtoothContrastImage2, sawtoothContrastImage1);With this change, the error message should disappear.