私は、霧の日に撮影されたように画像を変更するために白黒(白黒)のフォグフィルタを書きます。これを行うには、画像内のすべての値を、値そのものの横の値(4または8)と0〜255((short)(Math.random() * 256
)の乱数の平均値に変更します。私の先生は週末には助けに応じません。モノクロームフォグフィルタの書き直し
私はここにいます: イメージを白黒にするため、コードを改善しました。しかし、私はそれが白黒以上に際立つと思った。私は、割り当てが尋ねたことを少なくとも私がしっかりしていることを確認したい。
教師は、この割り当ておよび画像(.JPG画像) java.lang.Objectの拡張byjavaを提供インタフェース
ImageProviderクラスための彼自身のクラスの数を設計しました。 java.awt.image.ImageObserver、java.awt.MenuContainer、java.io.Serializableの
:awt.Component はbyimagelab.ImgProviderすべての実装されたインタフェースを拡張しました
ImageLabクラス java.lang.Objectの拡張byimagelab.ImageLab
ImageLabは、画像フィルタの開発のためのプラットフォームです。 ImageLabは、使用可能なすべてのフィルタ(ImageFilterインターフェイスを実装する.classファイル@see ImageFilter)のメニューを構築することから始まります。
インタフェースのImageFilter
パブリックインターフェイスのImageFilter
のImageFilterインターフェースは、それぞれの画像フィルタにより実装されています。
実装の詳細プログラム のフォーマットあなたはフィルタがラインに配置することによって、フィルタパッケージのメンバーであることを示す必要があり、フィルタの書き込み: パッケージフィルターを、 .javaファイルの一番上にあります。
フィルタでImageFilterインターフェイスを見つけることができるので、次の行を置く必要があります。 import imagelab。*;ファイル内の2行目に表示されます。
親ディレクトリ(サブディレクトリとしてimagelabとフィルタを持つディレクトリ)およびタイプに行き、(その呼ばMyFilter.javaを想定して)あなたのフィルタをコンパイルするには:imageLabを実行するには javacのフィルタ/ MyFilter.java
、あなたは同じディレクトリと型にする必要があります: Javaのimagelab.ImageLab
package filters;
import imagelab.*;
public class Monochrome implements ImageFilter {
ImgProvider filteredImage;
public void filter (ImgProvider ip) {
short[][] mono = ip.getBWImage();//Convert the picture to B&W
short[][] mono2 = new short[mono.length][mono[0].length];
/**Go through both arrays and change every value in the image to the average of the value itself, the values next to it (4 or all 8) and a random value from 0 to 255
*/
for (int r = 1; r<mono.length-1; r++) {
for (int c = 1; c < mono[0].length-1; c++) {
int val = mono[r][c];
val += ((short)Math.random()*256); //random number
val += mono[r-1][c];
val += mono[r+1][c];
val += mono[r][c-1];
val += mono[r][c+1];
val /= 5;
val = (val < 0) ? -val : val;
if (val > 255) val = 255;
mono2[r][c] = (short)((val < 0) ? -val : val);
}//for c
}//for r;
filteredImage = new ImgProvider(); //create the new .jpg image
filteredImage.setBWImage(mono2); //set it to B&W using the monochrome settings
filteredImage.showPix("Monochrome of original image"); //label the image
}//filter
public ImgProvider getImgProvider() {
return filteredImage;
}//getImgProvider
public String getMenuLabel() {
return "Monochrome";
} //getMenuLabel
}