/ Создаем гистограмму функции processImage() private void histogramProcess() { //…
- User
/ Создаем гистограмму функции processImage() private void histogramProcess() { // Создаем гистограмму исходного изображения 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]++; } }
// Создаем окно для отображения гистограммы JFrame histogramFrame = new JFrame(“Гистограмма”); histogramFrame.setLayout(new GridLayout(1, 2, 5, 5));
// Создаем панель для гистограммы JPanel histogramPanel = new JPanel(); histogramPanel.setLayout(new BorderLayout()); histogramPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), “Изображение”));
// Создаем компонент для рисования гистограммы JPanel histogramComponent = 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); } } }; histogramComponent.setPreferredSize(new Dimension(256, 300));
histogramPanel.add(histogramComponent, BorderLayout.CENTER);
histogramFrame.add(histogramPanel); histogramFrame.pack(); histogramFrame.setLocationRelativeTo(null); histogramFrame.setVisible(true); }
// Создаем гистограмму функции brightnessImage() private void histogramBrightness() { // Создаем изображение яркости в диапазоне [100, 200] BufferedImage brightnessSliceImage = brightnessSlice(image, 100, 200);
// Создаем гистограмму изображения яркости int[] histogram = 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); histogram[brightness]++; } }
// Создаем окно для отображения гистограммы JFrame histogramFrame = new JFrame(“Гистограмма”); histogramFrame.setLayout(new GridLayout(1, 2, 5, 5));
// Создаем панель для гистограммы JPanel histogramPanel = new JPanel(); histogramPanel.setLayout(new BorderLayout()); histogramPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), “Изображение”));
// Создаем компонент для рисования гистограммы JPanel histogramComponent = 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); } } }; histogramComponent.setPreferredSize(new Dimension(256, 300));
histogramPanel.add(histogramComponent, BorderLayout.CENTER);
- Assistant
ент для рисования гистограммы JPanel histogramComponent = 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); } } }; histogramComponent.setPreferredSize(new Dimension(256, 300));
histogramPanel.add(histogramComponent, BorderLayout.CENTER);
histogramFrame.add(histogramPanel); histogramFrame.pack(); histogramFrame.setLocationRelativeTo(null); histogramFrame.setVisible(true); }
- User
- Assistant
private void histogramProcess() { // Создаем гистограмму исходного изображения 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]++; } }
// Создаем окно для отображения гистограмм JFrame histogramFrame = new JFrame