الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

معالجة الصور

بدأه mr.beshoy في 20 ديسمبر 2009 · 15 رد · 1,665 مشاهدة · في JavaSE
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

سلام للجميع

------------

أنا اليوم بقرأ فى معالجة الصور بالجافا

هل أحد لديه معلومات او مصادر كويسة لهذا الموضوع بالجافا

أنا بقرأ من هذا المصدر لكن مش واضح للدرجة :

http://www.javaworld.com/javaworld/jw-09-1998/jw-09-media.html

شكراً مقدماً

#2

400 Processing Image Pixels using Java, Getting Started

402 Processing Image Pixels using Java, Creating a Spotlight

404 Processing Image Pixels Using Java: Controlling Contrast and Brightness

406 Processing Image Pixels, Color Intensity, Color Filtering, and Color Inversion

408 Processing Image Pixels, Performing Convolution on Images

410 Processing Image Pixels, Understanding Image Convolution in Java

412 Processing Image Pixels, Applying Image Convolution in Java, Part 1

414 Processing Image Pixels, Applying Image Convolution in Java, Part 2

416 Processing Image Pixels, An Improved Image-Processing Framework in Java

418 Processing Image Pixels, Creating Visible Watermarks in Java

450 A Framework for Experimenting with Java 2D Image-Processing Filters

452 Using the Java 2D LookupOp Filter Class to Process Images

454 Using the Java 2D AffineTransformOp Filter Class to Process Images

456 Using the Java 2D LookupOp Filter Class to Scramble and Unscramble Images

458 Using the Java 2D BandCombineOp Filter Class to Process Images

460 Using the Java 2D ConvolveOp Filter Class to Process Images

462 Using the Java 2D ColorConvertOp and RescaleOp Filter Classes to Process Images
1
#3

نفس المصادر الى شفتها أثناء بحثى

لكن أنا كنت مفكر فى حاجات غير كده

فى حاجات مش فاهمها كويس

#4

لو سمحتم ممكن توضيح لل PixelGrabber

أنا قرأت عنه بس الفكرة مش متضحة معايا ...

شكراً

#5

هنا كتبت كود بسيط لمحاولة استخراج ال pixels من الصورة

اولاً : أنا أرى ان طريقتى غير مرتبة و ناقصة

ثانياً : بيعطينى رسالة Error يقول فيها : javax.imageio.IIOException: Can't read input file!

لم يقرأ الملف المُمرر له .

الكود

----------

import java.awt.Dimension;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.PixelGrabber;
import java.io.File;
import javax.imageio.ImageIO;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.UIManager;

public class ProcessImageTest extends JFrame {

    private Image image;
    private PixelGrabber pixelGrabber;
    private Object pixel;
    private JPanel panel;
    private JButton button;

    public ProcessImageTest() {
        panel = new JPanel();
        button = new JButton("get pixels");
        panel.add(button);
        getContentPane().add(panel);
        try {
            image = ImageIO.read(new File("one.jpg"));
        } catch (Exception e) {
            e.printStackTrace();
        }

        pixelGrabber = new PixelGrabber(image, 0, 0, -1, -1, false);
        pixel = pixelGrabber.getPixels();
        button.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                JOptionPane.showMessageDialog(null, pixel);
            }
        });
    }

    public static void main(String[] args) {
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (Exception e) {
        }
        ProcessImageTest processImageTest = new ProcessImageTest();
        processImageTest.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        processImageTest.setSize(new Dimension(600, 300));
        processImageTest.setLocationRelativeTo(null);
        processImageTest.setVisible(true);
        processImageTest.setExtendedState(MAXIMIZED_BOTH);

    }
}

و أيضاً الكود فى المرفقات ....

عاوز اعرف الطريقة السليمة لإستعمال هذا ال class

شكراً مقدماً

processImage.rar

#6

الأخ بيشوي

أذكر أنك أخبرتني أن مشروعك هو إخفاء البيانات في الصورة

كل ما تحتاجه هو تغيير قيمة البكسل من قيمة إلى قيمة أخرى

أقصد لست بحاجة لتعلم الكثير عن معالجة الصور

ركز على فهم طرق إخفاء البيانات أكثر

http://modonat-alaa.freehostia.com/2008/08/%D9%84%D9%85%D8%AD%D8%A9-%D8%AC%D8%A7%D9%81%D8%A7%D9%88%D9%8A%D8%A9-16-%D9%85%D8%B9%D8%A7%D9%84%D8%AC%D8%A9-%D8%A7%D9%84%D8%B5%D9%88%D8%B1-%D8%A7%D9%84%D8%B1%D9%82%D9%85%D9%8A%D8%A9/

http://modonat-alaa.freehostia.com/2008/08/%D9%85%D8%B9%D8%A7%D9%84%D8%AC%D8%A9-%D8%A7%D9%84%D8%B5%D9%88%D8%B1-%D8%A7%D9%84%D8%B1%D9%82%D9%85%D9%8A%D8%A9-%D8%A7%D9%84%D8%AC%D8%B2%D8%A1-%D8%A7%D9%84%D8%AB%D8%A7%D9%86%D9%8A/

تحياتي

حزمة المحرك الإصدارة 0.8

أي أحد يجد أني ظلمته فليراسلني

وبإذن الله لو كان له حق سيأخذه

728x90.png

#7

شكراً

----------

أنا كل الى كنت عاوز اعمله فقط الحصول على قيم ال pixel الخاص للصورة حتى يمكننى تغييرها

-------------------------------------------

ياريت أحد يرى الشفيرة

شكراً

#8

يجب أن تمرر مصفوفة int لconstructor لتخزين فيم الpixels، يعني لازم تستعمل هذا الconstructor

public PixelGrabber(Image img, int x, int y, int w, int h, int[] pix, int off, int scansize)

لملء لمصفوفة يجب المناداة على grabPixels

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.awt.image.PixelGrabber;
import java.io.File;
import java.util.Arrays;
import javax.imageio.ImageIO;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.UIManager;

public class ProcessImageTest extends JFrame {

	private BufferedImage image;
	private PixelGrabber pixelGrabber;
	private int[] pixel;
	private JPanel panel;
	private JButton button;

	public ProcessImageTest() {
		panel = new JPanel();
		button = new JButton("get pixels");
		button.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent e) {
				JOptionPane.showMessageDialog(null, pixel);
			}
		});
		panel.add(button);
		getContentPane().add(panel);
		try {
			image = ImageIO.read(new File("img.jpg"));
			pixel = new int[image.getWidth() * image.getHeight()];
			pixelGrabber = new PixelGrabber(image, 0, 0, image.getWidth(), image.getHeight(), pixel, 0, image.getWidth());
			if (pixelGrabber.grabPixels()) {
				System.out.println(Arrays.toString(pixel));
			} else {
				JOptionPane.showMessageDialog(null, "Cannot grab pixels");
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static void main(String[] args) {
		try {
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		} catch (Exception e) {
		}
		ProcessImageTest processImageTest = new ProcessImageTest();
		processImageTest.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		processImageTest.setSize(new Dimension(600, 300));
		processImageTest.setLocationRelativeTo(null);
		processImageTest.setVisible(true);
	}
}
#9

شوف يا عصام طبقت كودك كما هو

بس اختلفنا فى االصورة المستعملة

و عملت كده

image = ImageIO.read(new File("one.jpg"));

الراجل بيعترض و بيقولى

javax.imageio.IIOException: Can't read input file!

غير كده انا هدفى من الزرار اطلع قيم ال pixels فى Dialog

معلش طول بالك علينا يا عصام :)

شكراً

#10

استعمل صورة أخرى، لان المشكل من الصورة أو من المسار الذي تحدده. لم أحصل على الخطأ الذي تتكلم عنه

محتوى المصفوفة pixel كبير جدا ولا يصلح للظهور في dialog

#11

شوف يا أخ عصام

غيرت الصورة و مع ذلك المشكلة قائمة ....

و فكرت اننا نعرض ال pixels على TextArea موضوعة داخل panel و لكنها لا تظهر عن الضغط على الزر

الكود فى المرفقات

شكراً جزيلاً لتعبك

processImage.rar

#12

عرفت احل مشكلة ال exception الذى يحدث بسبب أنه لم يستطع قراءة الصورة

استعملت خاصية ال

 getClass().getResourcer("image name")

المشكلة أنى لما بضغط الزر أريده أن يعرض ال pixels على textarea البرنامج بيعلق

الكود :

-------------

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.awt.image.PixelGrabber;
import java.util.Arrays;
import javax.imageio.ImageIO;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollBar;
import javax.swing.JTextArea;
import javax.swing.UIManager;

public class ProcessImageTest extends JFrame {

    private BufferedImage image;
    private PixelGrabber pixelGrabber;
    private int[] pixel;
    private JPanel panel, pixelPanel;
    private JButton button;
    private JTextArea area;
    private JScrollBar scrollBar;

    public ProcessImageTest() {
        panel = new JPanel(null);
        panel.setBounds(100, 10, 200, 100);
        pixelPanel = new JPanel();
        pixelPanel.setBounds(50,10, 50, 100);

        button = new JButton("get pixels");
        button.setBounds(50,10, 100,50);
        panel.add(button);

        area = new JTextArea();
        area.setBounds(50,10,50,100);
        pixelPanel.add(area);
        panel.add(pixelPanel);

        pixelPanel.setVisible(false);
        getContentPane().add(panel);
        try {
            image = ImageIO.read(getClass().getResource("one.jpg"));
            pixel = new int[image.getWidth() * image.getHeight()];
            pixelGrabber = new PixelGrabber(image, 0, 0, image.getWidth(), image.getHeight(), pixel, 0, image.getWidth());
            if (pixelGrabber.grabPixels()) {
                button.addActionListener(new ActionListener() {

                    public void actionPerformed(ActionEvent e) {
                        area.setText(Arrays.toString(pixel));
                        pixelPanel.setVisible(true);
                    }
                });
            } else {
                JOptionPane.showMessageDialog(null, "Cannot grab pixels");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (Exception e) {
        }
        ProcessImageTest processImageTest = new ProcessImageTest();
        processImageTest.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        processImageTest.setSize(new Dimension(600, 300));
        processImageTest.setLocationRelativeTo(null);
        processImageTest.setVisible(true);
    }
}

شكراً

#13
/*
First I'm sorry for this long english post, 
but its difficult to write all this in arabic

Sorry for my late reply, I promised to write it faster but I was really busy. 
So now your code for grabbing the pixels seems to be correct

The image path is bad, don't use getClass().getResource("one.jpg")
this is not recommended at all, use ImageIO.read(new File("one.jpg"));
and place the image in the root directory of your project, or create a folder of images
but don't place it inside the package.

Now we have one dimensional array which contains all the pixels info, but modifications
inside this array is quite difficult, so we will convert the 1 dimensional array 
to 3 dimensional array. In the 3 dim array each element represents one colored pixel,
while one dimension will represent rows, one dimension will represent columns and the 3rd 
dimension will represent the color and transparency of the pixel.

A pixel is represented by four unsigned 8-bit bytes of data. Three of those four 
bytes represent the colors red, green, and blue (RGB).  The fourth byte, is the alpha byte, 
represents transparency. The value of each color is between 0 and 255.

This is the structure of the 3 dimentional array
int[][][] threeDPixels = new int[imgRows][imgCols][4];

The third dimension of size for consists of:
0 alpha or transparency
1 red
2 green
3 blue

Filling the 3 dim array requires the usage of bitwise operators ("AND &" and "right shift")

I modified your code that you can see below to convert the 1D to 3D array.
I hope its understandable, if something is not clear you can ask.

One reason why we & 0xFF during the conversion is that byte's are signed, 
so if "data" is a byte array, and some of the bytes are 128 or above, then they 
will be interpreted as being negative. and when they are promoted to integers 
or longs, they will still be negative (i.e. they will be filled with 1's on the left). 
If you want the byte to just take on a value between 0 and 255, then you can AND it with 0xFF.


At this point you have to start playing with the colors, so at some pixels you need to add the letters
of your message. The LSB method is to use the LSB of each color in the pixel.
Each character in your text message will be represented by 6 bits. 
Replacing the two least-significant bits (LSB) in the red, green, 
and blue values for a given pixel by the three groups of two bits.  
So each pixel can carry one six-bit character.

I will stop here for now, you can try to insert a message to the pixels of the 3 dim array.
I will continue later about this insertion of text. 

Hope what I wrote was helpful for you and others, and again sorry for the english post.

*/

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.awt.image.PixelGrabber;
import java.io.File;
import java.util.Arrays;
import javax.imageio.ImageIO;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollBar;
import javax.swing.JTextArea;
import javax.swing.UIManager;

public class ProcessImageTest extends JFrame {

    private BufferedImage image;
    private PixelGrabber pixelGrabber;
    private int[] pixel;
    private JPanel panel, pixelPanel;
    private JButton button;
    private JTextArea area;
    private JScrollBar scrollBar;
    private int[][][] threeDimPixels;

    public ProcessImageTest() {
        panel = new JPanel(null);
        panel.setBounds(100, 10, 200, 100);
        pixelPanel = new JPanel();
        pixelPanel.setBounds(50,10, 50, 100);

        button = new JButton("get pixels");
        button.setBounds(50,10, 100,50);
        panel.add(button);

        area = new JTextArea();
        area.setBounds(50,10,50,100);
        pixelPanel.add(area);
        panel.add(pixelPanel);

        pixelPanel.setVisible(false);
        getContentPane().add(panel);
        try {
            image = ImageIO.read(new File("one.jpg"));
            pixel = new int[image.getWidth() * image.getHeight()];
            pixelGrabber = new PixelGrabber(image, 0, 0, image.getWidth(), image.getHeight(), pixel, 0, image.getWidth());
            if (pixelGrabber.grabPixels()) {
                button.addActionListener(new ActionListener() {

                    public void actionPerformed(ActionEvent e) {
                        area.setText(Arrays.toString(pixel));

                        threeDimPixels = OneDimToThreeDim(pixel, image.getWidth(), image.getHeight());
                        if(threeDimPixels != null && threeDimPixels.length > 0)
                        {
                        for(int i=0; i<threeDimPixels.length; i++)
                        {
                             for(int j=0; j<threeDimPixels.length; j++)
                             {
                                 // just to be sure that u have the pixels in the 3d array
                                 // its a consuming operation
                                 // comment it out after testing
                                 System.out.println("Color at [" + i + "][" + j + "]   "
                                         + threeDimPixels[j][0] + " "
                                         + threeDimPixels[j][1] + " "
                                         + threeDimPixels[j][2] + " "
                                         + threeDimPixels[j][3]);

                             }

                        }
                        }
                        else
                        {
                            System.out.println("null");
                        }
                        pixelPanel.setVisible(true);
                    }
                });
            } else {
                JOptionPane.showMessageDialog(null, "Cannot grab pixels");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    // Conversion to 3 dim array
    int[][][] OneDimToThreeDim(
            int[] oneDPix,int imgCols,int imgRows){
    //creation of 3 dim array
    int[][][] data = new int[imgRows][imgCols][4];

    for(int row = 0;row < imgRows;row++){
      //Extract a row of pixel data into a
      // temporary array of ints
      int[] aRow = new int[imgCols];
      for(int col = 0; col < imgCols;col++)
      {
        int element = row * imgCols + col;
        aRow[col] = oneDPix[element];
      }

      //Move the color data into the 3D array.
      for(int col = 0;col < imgCols;col++){
        //Alpha data
        data[row][col][0] = (aRow[col] >> 24)
                                          & 0xFF;
        //Red data
        data[row][col][1] = (aRow[col] >> 16)
                                          & 0xFF;
        //Green data
        data[row][col][2] = (aRow[col] >> 8)
                                          & 0xFF;
        //Blue data
        data[row][col][3] = (aRow[col])
                                          & 0xFF;
      }
    }
    return data;
  }

    public static void main(String[] args) {
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (Exception e) {
        }
        ProcessImageTest processImageTest = new ProcessImageTest();
        processImageTest.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        processImageTest.setSize(new Dimension(600, 300));
        processImageTest.setLocationRelativeTo(null);
        processImageTest.setVisible(true);
    }
}
1
#14

ما بيعلق

لكنك شغال على نفس ال thread من الطبيعي ان يتم اخذ البيكسيلز و تخزينهم بالمصفوفة و من ثم تحويلها ل string من ثم عرضها في ال مربع النص

خلال اتمام هذه العمليات لن تستطيع اجراء اي عملية لحين انتهائها فبيظهر انه معلق !!

جرب التالي

                    public void actionPerformed(ActionEvent e) {
                        new Thread() {

                            public void run() {
                                for (int ii = 0; ii < pixel.length; ii++) {
                                    System.out.println(pixel[ii]);
                                }
                            }
                        }.start();
                    }

يفضل انت تعمل على صور grayscale و بعدها دراسة ال colors models مثل rgb

Unix is user friendly. It's just selective about who its friends are .

#15

بصراحة الأخ null one مفهمتش كويس الدالة OneDimToThreeDim()

و مش فاهم الهدف من ال oxFF معلش وضعهها تانى بأسلوب سهل

او أى احد من اخوة المنتدى يعرف يقول

شكراً لكم جميعاً

#16

أنا بعد محاولات و بحث كده أسطعت فهم لحد ما فكرة ال 0xFF and 0x0F

لكن معلش أنا عاوز بردو اسمعها منك عشان افهمها أكتر و اتاكد من فهمى ....

---------------------------------------------------------------------------

أثناء بحثى وجدت مصدر شارح ال steganography على ال LSB

و عامل دالة ادخال النص و دالة استخراج النص

http://www.dreamincode.net/forums/showtopic27950.htm

انا مش فاهم كويس دالة ادخال النص و خصوصاً الجزء هذا :

for(int bit=7; bit>=0; --bit, ++offset)
        {
                int b = (add >>> bit) & 1;
                image[offset] = (byte)((image[offset] & 0xFE) | b );
        }

و ايه هو ال offset ده و أيه فكرة ال rigth shift و ال & 0xFE) | b

ياريت تجاوبنى على التساؤلت هذه ....

-------------------------------------------------------------

انا كل الى فاهمه عن ال LSB

انى بستبدل أول بت - على اليمين - فى الصورة فى اول byte باول بت موجود فى اول حرف فى الرسالة و هكذا

شكراً مقدماً

سلام

مواضيع مشابهة

عدد الزوار حالياً

المتواجدون خلال آخر دقيقتين · يتحدّث كل ٣٠ ثانية

—الإجمالي—أعضاء مسجّلون—زوار بدون تسجيل

جارٍ التحقق من المتواجدين…