Last night, I saw an article entitled "The computer was so easy to use when it was shaking." It mentioned a jitter technology that is often used by computers to process digital signals, I think it is quite interesting, so today I wrote a small program that generates binary images using the evil JAVA.
:
The acm jtf package used in the program can be found at http://jtf.acm.org/here. We recommend that you go to Eric S. Robert TS's "the art and Science of Java", which is a good entry material and can improve your English Reading Ability by the way.
Main program code:
import java.awt.*;import java.awt.event.ActionEvent;import java.awt.image.BufferedImage;import java.io.File;import java.io.IOException;import acm.program.*;import acm.graphics.*;import javax.imageio.ImageIO;import javax.swing.*;public class test_filter extends GraphicsProgram{public void init(){setBackground(Color.gray);slider = new JSlider(0,100,50);add(new JButton("Open Image"),SOUTH);add(new JButton("Process"),SOUTH);add(new JLabel("Dark "),SOUTH);add(slider,SOUTH);add(new JLabel("Bright"),SOUTH);add(new JButton("Save"),SOUTH);addActionListeners();}public void actionPerformed(ActionEvent e){String cmd = e.getActionCommand();if(cmd.equals("Open Image")) openTarget();if(cmd.equals("Process")) process();if(cmd.equals("Save")) save();}private void openTarget(){JFileChooser chooser = new JFileChooser();int fid = chooser.showOpenDialog(this);if(fid == chooser.APPROVE_OPTION){File file = chooser.getSelectedFile();if(file.getName().endsWith(".jpg") || file.getName().endsWith(".JPG")){target = null;target = new GImage(file.getPath());setScale(target);is_target_ready = true;target_thumbnail = thumbnail(target);pic_width = target_thumbnail.getWidth();pic_height = target_thumbnail.getHeight();removeAll();add(target_thumbnail,0,0);}}}private void process(){if(!is_target_ready) return ;double factor = slider.getValue()/50.0;result = dsp.actBwFilter(target,factor);GImage result_thumbnail = thumbnail(result);add(result_thumbnail,pic_width,0);is_result_ready = true;}private void save(){if(!is_result_ready) return ;try {JFileChooser chooser = new JFileChooser();int fid = chooser.showSaveDialog(this);if(fid==JFileChooser.APPROVE_OPTION){File file = chooser.getSelectedFile();ImageIO.write(toBufferedImage(result), "jpg", file);}} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}}private BufferedImage toBufferedImage(GImage image){int[][] array = image.getPixelArray();int width = array[0].length;int height = array.length;BufferedImage bimg = new BufferedImage(width,height,BufferedImage.TYPE_INT_RGB);for(int i=0;i
Two-value graph generation function:
public static GImage actBwFilter(GImage image){return actBwFilter(image,1);}public static GImage actBwFilter(GImage image,double factor){image = bwFilter(image);int[][] array = image.getPixelArray();RandomGenerator rgen = RandomGenerator.getInstance();int width = array[0].length;int height = array.length;for(int i=0;i