色がないのに色がついて見える補色残像について
2007/12/23
groovy
java
webstart
補色残像がおもしろかったので、とりあげてみます。
補色残像とは?
補色残像というのは、色順応によって、色がないもの(モノクロ写真とか)を見たときに色がついてみえたりすることのようです。
プログラム
起動して画面に画像をドロップします。
補色画像ボタンを押して30秒ぐらいみます。
グレースケール画像ボタンを素早く押しますすると、画像に色がついてみえます(みえるかも...)。
プログラム(説明,コード)
package main.afterimage
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.geom.Area;
import java.awt.geom.RoundRectangle2D;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.URL;
import javax.imageio.ImageIO;
import org.jdesktop.swingx.JXImageView;
import org.jdesktop.swingx.graphics.GraphicsUtilities;
import groovy.swing.SwingBuilder
import java.awt.BorderLayout
import javax.swing.JFrame
import javax.swing.BoxLayout
import com.jhlabs.image.*
public class Main {
static void main(args) {
def swing = new SwingBuilder()
ImageView imageView = new ImageView()
def frame =
swing.frame(title:'Frame', size:[500,300], defaultCloseOperation:JFrame.EXIT_ON_CLOSE, pack:true, show:true) {
borderLayout()
panel(constraints:BorderLayout.SOUTH){
button(text:'補色画像',
actionPerformed: {
imageView.setInvert()
println "clicked"})
button(text:'グレースケール画像',
actionPerformed: {
imageView.setGray()
println "clicked"})
}
widget(imageView)
}
frame.setBounds(100,100,400,300)
//frame.pack()
frame.show()
}
}
public class ImageView extends JXImageView {
public ImageView() {
super();
initialize();
setDragEnabled(true);
setEditable(true);
}
private void initialize() {
this.setSize(new Dimension(316, 285));
}
BufferedImage originalImage;
BufferedImage gray;
BufferedImage invert;
@Override
public void setImageString(String url) throws IOException {
System.out.println("new image");
this.originalImage = null;
try {
originalImage = ImageIO.read(new URL(url));
processImage()
} catch (Exception e) {
e.printStackTrace();
}
super.setImageString(url);
}
public void setInvert(){
if (this.originalImage != null) {
setImage(invert);
}
}
public void setGray(){
if (this.originalImage != null) {
setImage(gray);
}
}
public void processImage() {
if (this.originalImage != null) {
try {
BufferedImage image = GraphicsUtilities
.toCompatibleImage(originalImage);
int w = image.getWidth();
int h = image.getHeight();
gray = new BufferedImage(w, h,
BufferedImage.TYPE_INT_ARGB);
invert = new BufferedImage(w, h,
BufferedImage.TYPE_INT_ARGB);
GrayscaleFilter gfilter = new GrayscaleFilter()
gfilter.filter(image, gray)
InvertFilter ifilter = new InvertFilter()
ifilter.filter(image, invert)
setImage(invert);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.geom.Area;
import java.awt.geom.RoundRectangle2D;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.URL;
import javax.imageio.ImageIO;
import org.jdesktop.swingx.JXImageView;
import org.jdesktop.swingx.graphics.GraphicsUtilities;
import groovy.swing.SwingBuilder
import java.awt.BorderLayout
import javax.swing.JFrame
import javax.swing.BoxLayout
import com.jhlabs.image.*
public class Main {
static void main(args) {
def swing = new SwingBuilder()
ImageView imageView = new ImageView()
def frame =
swing.frame(title:'Frame', size:[500,300], defaultCloseOperation:JFrame.EXIT_ON_CLOSE, pack:true, show:true) {
borderLayout()
panel(constraints:BorderLayout.SOUTH){
button(text:'補色画像',
actionPerformed: {
imageView.setInvert()
println "clicked"})
button(text:'グレースケール画像',
actionPerformed: {
imageView.setGray()
println "clicked"})
}
widget(imageView)
}
frame.setBounds(100,100,400,300)
//frame.pack()
frame.show()
}
}
public class ImageView extends JXImageView {
public ImageView() {
super();
initialize();
setDragEnabled(true);
setEditable(true);
}
private void initialize() {
this.setSize(new Dimension(316, 285));
}
BufferedImage originalImage;
BufferedImage gray;
BufferedImage invert;
@Override
public void setImageString(String url) throws IOException {
System.out.println("new image");
this.originalImage = null;
try {
originalImage = ImageIO.read(new URL(url));
processImage()
} catch (Exception e) {
e.printStackTrace();
}
super.setImageString(url);
}
public void setInvert(){
if (this.originalImage != null) {
setImage(invert);
}
}
public void setGray(){
if (this.originalImage != null) {
setImage(gray);
}
}
public void processImage() {
if (this.originalImage != null) {
try {
BufferedImage image = GraphicsUtilities
.toCompatibleImage(originalImage);
int w = image.getWidth();
int h = image.getHeight();
gray = new BufferedImage(w, h,
BufferedImage.TYPE_INT_ARGB);
invert = new BufferedImage(w, h,
BufferedImage.TYPE_INT_ARGB);
GrayscaleFilter gfilter = new GrayscaleFilter()
gfilter.filter(image, gray)
InvertFilter ifilter = new InvertFilter()
ifilter.filter(image, invert)
setImage(invert);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
参考
Gon's BLOG: Color Illusion 補色残像
sasapong's room: 補色残像てんこもり
色順応
Color Illusion Tutorial
: