Appearance
question:Переделай код, чтобы вводить порог максимальный. private void contrastImage() { if (image != null) { BufferedImage contrastStretchedImage = linearContrastStretch(image); setImageIcon(contrastStretchedImage); saveImage(contrastStretchedImage); // Получение порогового значения String thresholdString = JOptionPane.showInputDialog(this, "Введите пороговое значение: "); int threshold = Integer.parseInt(thresholdString); // Создаем гистограмму исходного изображения 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[] contrastStretchedHistogram = new int[256]; for (int i = 0; i < contrastStretchedImage.getWidth(); i++) { for (int j = 0; j < contrastStretchedImage.getHeight(); j++) { int pixel = contrastStretchedImage.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); contrastStretchedHistogram[brightness]++; } } // Создаем окно для отображения гистограмм JFrame histogramFrame = new JFrame("Гистограммы"); histogramFrame.setLayout(new GridLayout(2, 2, 10, 10)); // Создаем панель для гистограммы исходного изображения JPanel histogramPanel1 = new JPanel() { @Override protected void paintComponent(Graphics g) { super.paintComponent(g); int max = Arrays.stream(histogram).max().getAsInt(); for (int i = 0; i < 256; i++) { int height = (int) (300.0 * histogram[i] / max); g.fillRect(i, 300 - height, 1, height); } } }; histogramPanel1.setPreferredSize(new Dimension(256, 300)); // Создаем панель для гистограммы преобразованного изображения JPanel histogramPanel2 = new JPanel() { @Override protected void paintComponent(Graphics g) { super.paintComponent(g); int max = Arrays.stream(contrastStretchedHistogram).max().getAsInt(); for (int i = 0; i < 256; i++) { int height = (int) (300.0 * contrastStretchedHistogram[i] / max); g.fillRect(i, 300 - height, 1, height); } } }; histogramPanel2.setPreferredSize(new Dimension(256, 300)); histogramFrame.add(new JLabel("Гистограмма исходного изображения")); histogramFrame.add(new JLabel("Гистограмма преобразованного изображения")); histogramFrame.add(histogramPanel1); histogramFrame.add(histogramPanel2); histogramFrame.pack(); histogramFrame.setLocationRelativeTo(null); histogramFrame.setVisible(true); } }
answer:private void contrastImage() { if (image != null) { BufferedImage contrastStretchedImage = linearContrastStretch(image); setImageIcon(contrastStretchedImage); saveImage(contrastStretchedImage); // Get maximum threshold value String thresholdString = JOptionPane.showInputDialog(this, "Введите максимальное пороговое значение: "); int maxThreshold = Integer.parseInt(thresholdString); // Create histogram for original image int[] histogram = createHistogram(image); // Create histogram for contrast stretched image int[] contrastStretchedHistogram = createHistogram(contrastStretchedImage); // Create window for displaying histograms JFrame histogramFrame = new JFrame("Гистограммы"); histogramFrame.setLayout(new GridLayout(2, 2, 10, 10)); // Panel for original image histogram JPanel histogramPanel1 = createHistogramPanel(histogram); histogramPanel1.setBorder(BorderFactory.createTitledBorder("Гистограмма исходного изображения")); // Panel for contrast stretched image histogram JPanel histogramPanel2 = createHistogramPanel(contrastStretchedHistogram); histogramPanel2.setBorder(BorderFactory.createTitledBorder("Гистограмма преобразованного изображения")); histogramFrame.add(histogramPanel1); histogramFrame.add(histogramPanel2); // Create panel for threshold slider JPanel thresholdPanel = new JPanel(new BorderLayout()); JSlider thresholdSlider = new JSlider(0, maxThreshold); thresholdSlider.setValue(maxThreshold/2); JLabel thresholdLabel = new JLabel("Пороговое значение: " + thresholdSlider.getValue()); thresholdSlider.addChangeListener(e -> { int threshold = thresholdSlider.getValue(); thresholdLabel.setText("Пороговое значение: " + threshold); BufferedImage thresholdedImage = thresholdImage(contrastStretchedImage, threshold); setImageIcon(thresholdedImage); }); thresholdPanel.add(thresholdLabel, BorderLayout.WEST); thresholdPanel.add(thresholdSlider, BorderLayout.CENTER); thresholdPanel.setBorder(BorderFactory.createTitledBorder("Настройка порогового значения")); histogramFrame.add(thresholdPanel); histogramFrame.pack(); histogramFrame.setLocationRelativeTo(null); histogramFrame.setVisible(true); } } private BufferedImage thresholdImage(BufferedImage image, int threshold) { BufferedImage thresholdedImage = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_RGB); 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; // Calculate brightness of pixel int brightness = (int) (0.2126 * red + 0.7152 * green + 0.0722 * blue); // Set pixel to white if greater than threshold, else black if (brightness >= threshold) { thresholdedImage.setRGB(i, j, Color.WHITE.getRGB()); } else { thresholdedImage.setRGB(i, j, Color.BLACK.getRGB()); } } } return thresholdedImage; }
question:Переделай код, чтобы вводить порог максимальный. private void contrastImage() { if (image != null) { BufferedImage contrastStretchedImage = linearContrastStretch(image); setImageIcon(contrastStretchedImage); saveImage(contrastStretchedImage); // Получение порогового значения String thresholdString = JOptionPane.showInputDialog(this, "Введите пороговое значение: "); int threshold = Integer.parseInt(thresholdString); // Создаем гистограмму исходного изображения 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[] contrastStretchedHistogram = new int[256]; for (int i = 0; i < contrastStretchedImage.getWidth(); i++) { for (int j = 0; j < contrastStretchedImage.getHeight(); j++) { int pixel = contrastStretchedImage.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); contrastStretchedHistogram[brightness]++; } } // Создаем окно для отображения гистограмм JFrame histogramFrame = new JFrame("Гистограммы"); histogramFrame.setLayout(new GridLayout(2, 2, 10, 10)); // Создаем панель для гистограммы исходного изображения JPanel histogramPanel1 = new JPanel() { @Override protected void paintComponent(Graphics g) { super.paintComponent(g); int max = Arrays.stream(histogram).max().getAsInt(); for (int i = 0; i < 256; i++) { int height = (int) (300.0 * histogram[i] / max); g.fillRect(i, 300 - height, 1, height); } } }; histogramPanel1.setPreferredSize(new Dimension(256, 300)); // Создаем панель для гистограммы преобразованного изображения JPanel histogramPanel2 = new JPanel() { @Override protected void paintComponent(Graphics g) { super.paintComponent(g); int max = Arrays.stream(contrastStretchedHistogram).max().getAsInt(); for (int i = 0; i < 256; i++) { int height = (int) (300.0 * contrastStretchedHistogram[i] / max); g.fillRect(i, 300 - height, 1, height); } } }; histogramPanel2.setPreferredSize(new Dimension(256, 300)); histogramFrame.add(new JLabel("Гистограмма исходного изображения")); histogramFrame.add(new JLabel("Гистограмма преобразованного изображения")); histogramFrame.add(histogramPanel1); histogramFrame.add(histogramPanel2); histogramFrame.pack(); histogramFrame.setLocationRelativeTo(null); histogramFrame.setVisible(true); } }
answer:private void contrastImage() { if (image != null) { BufferedImage contrastStretchedImage = linearContrastStretch(image); setImageIcon(contrastStretchedImage); saveImage(contrastStretchedImage); // Получение порогового значения String thresholdString = JOptionPane.showInputDialog(this, "Введите пороговое значение: "); int threshold = Integer.parseInt(thresholdString); // Создаем гистограмму исходного изображения 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[] contrastStretchedHistogram = new int[256]; for (int i = 0; i < contrastStretchedImage.getWidth(); i++) { for (int j = 0; j < contrastStretchedImage.getHeight(); j++) { int pixel = contrastStretchedImage.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); contrastStretchedHistogram[brightness]++; } } // Создаем окно для отображения гистограмм JFrame histogramFrame = new JFrame("Гистограммы"); histogramFrame.setLayout(new GridLayout(2, 2, 10, 10)); // Создаем панель для гистограммы исходного изображения JPanel histogramPanel1 = new JPanel() { @Override protected void paintComponent(Graphics g) { super.paintComponent(g); int max = Arrays.stream(histogram).max().getAsInt(); for (int i = 0; i < 256; i++) { int height = (int) (300.0 * histogram[i] / max); g.fillRect(i, 300 - height, 1, height); } } }; histogramPanel1.setPreferredSize(new Dimension(256, 300)); // Создаем панель для гистограммы преобразованного изображения JPanel histogramPanel2 = new JPanel() { @Override protected void paintComponent(Graphics g) { super.paintComponent(g); int max = Arrays.stream(contrastStretchedHistogram).max().getAsInt(); for (int i = 0; i < 256; i++) { int height = (int) (300.0 * contrastStretchedHistogram[i] / max); g.fillRect(i, 300 - height, 1, height); } } }; histogramPanel2.setPreferredSize(new Dimension(256, 300)); histogramFrame.add(new JLabel("Гистограмма исходного изображения")); histogramFrame.add(new JLabel("Гистограмма преобразованного изображения")); histogramFrame.add(histogramPanel1); histogramFrame.add(histogramPanel2); histogramFrame.pack(); histogramFrame.setLocationRelativeTo(null); histogramFrame.setVisible(true); } }
question:list 50 tavern names, d&d fantasy settings
answer:1. The Drunken Dragon 2. The Red Lion 3. The Rusty Axe 4. The Roaring Boar 5. The Golden Stag 6. The Black Rose 7. The Dragon's Den 8. The Silver Spoon 9. The Dancing Gnome 10. The Tipsy Kobold 11. The Laughing Goblin 12. The Bilgewater Inn 13. The Siren's Call 14. The Dark Forest Tavern 15. The Thirsty Mermaid 16. The Emerald Dragon 17. The Thirsty Troll 18. The Crown & Anchor 19. The Flying Griffin 20. The Iron Boar 21. The Broken Oar 22. The Blind Ogre 23. The Hungry Wolf 24. The Dragon's Breath 25. The Black Cat Inn 26. The Jolly Pirate 27. The Crystal Goblet 28. The Enchanted Garden 29. The Rusty Anchor 30. The Silent Wraith 31. The Blushing Fox 32. The Dragon's Eye 33. The Smoking Toad 34. The Rusty Horseshoe 35. The Glistening Nymph 36. The Mystic Mage 37. The Laughing Rat 38. The Royal Lion 39. The Bewitched Bat 40. The Cursed Cauldron 41. The Black Swan 42. The Blue Boar 43. The Brawling Bear 44. The Dragon's Claw 45. The Haunted Hound 46. The Scarlet Siren 47. The Shadowy Owl 48. The Starry Night Inn 49. The Whistling Wind 50. The Winking Warthog.
question:list 100 tavern names, one word each, d&d fantasy settings
answer:1. Drunken 2. Red 3. Rusty 4. Roaring 5. Golden 6. Black 7. Dragon's 8. Silver 9. Dancing 10. Tipsy 11. Laughing 12. Bilgewater 13. Siren's 14. Dark 15. Thirsty 16. Emerald 17. Flying 18. Iron 19. Broken 20. Blind 21. Hungry 22. Blushing 23. Smoking 24. Rusty 25. Silent 26. Jolly 27. Crystal 28. Enchanted 29. Royal 30. Bewitched 31. Cursed 32. Blue 33. Brawling 34. Haunted 35. Scarlet 36. Shadowy 37. Starry 38. Whistling 39. Winking 40. Alehouse 41. Taproom 42. Inn 43. Pub 44. Meadhall 45. Brewery 46. Tavern 47. Winebar 48. Cellar 49. Alehouse 50. Saloon 51. Barroom 52. Speakeasy 53. Whiskey 54. Beer 55. Wine 56. Mead 57. Brandy 58. Rum 59. Gin 60. Cider 61. Folly 62. Mug 63. Boar 64. Stag 65. Lion 66. Tiger 67. Bear 68. Wolf 69. Fox 70. Rat 71. Bat 72. Hedgehog 73. Badger 74. Squirrel 75. Raccoon 76. Mongoose 77. Skunk 78. Opossum 79. Armadillo 80. Possum 81. Rabbit 82. Hare 83. Beaver 84. Otter 85. Duck 86. Chicken 87. Gander 88. Goose 89. Turkey 90. Pheasant 91. Quail 92. Sparrow 93. Owl 94. Hawk 95. Eagle 96. Parrot 97. Falcon 98. Phoenix 99. Griffin 100. Chimera