Java OpenCVライブラリを使用して画像にノイズを追加するにはどうすればよいですか?
OpenCV を使用して指定された画像にノイズを追加する -
指定された画像の内容を Mat オブジェクトに読み取ります。
ノイズと結果を保存する 2 つの空の行列を作成します。
平均と標準偏差を保存する 2 つの MatOfDouble 行列を作成します。
meanStdDev() 関数を使用して、平均値と標準偏差の値を取得します。 randn() メソッドを使用して、ランダムな要素を含む行列を作成します (ノイズを保存するために使用されます)。
上記で作成したソース、平均、標準偏差をこのメソッドに渡します object.
最後に、ノイズ行列とソース行列が追加され、ターゲット行列として保存されます。
#例
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.IOException;
import javafx.application.Application;
import javafx.embed.swing.SwingFXUtils;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.image.ImageView;
import javafx.scene.image.WritableImage;
import javafx.stage.Stage;
import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.core.MatOfDouble;
import org.opencv.highgui.HighGui;
import org.opencv.imgcodecs.Imgcodecs;
public class AddingNoise extends Application {
public void start(Stage stage) throws IOException {
//Loading the OpenCV core library
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
//Reading the Image from the file
String file ="D://images//elephant.jpg";
Mat src = Imgcodecs.imread(file);
System.out.println("Image Loaded");
//Creating destination matrix
Mat dst = new Mat(src.rows(), src.cols(), src.type());
//Creating a matrix for the noise
Mat noise = new Mat(src.rows(), src.cols(), src.type());
//Calculating the mean and standard deviation
MatOfDouble mean = new MatOfDouble();
MatOfDouble dev = new MatOfDouble();
Core.meanStdDev(src, mean, dev);
//Filling the noise matrix
Core.randn(noise, mean.get(0,0)[0], dev.get(0,0)[0]);
//Adding noise to the destination
Core.add(src, noise, dst);
//Converting matrix to JavaFX writable image
Image img = HighGui.toBufferedImage(dst);
WritableImage writableImage= SwingFXUtils.toFXImage((BufferedImage) img, null);
//Setting the image view
ImageView imageView = new ImageView(writableImage);
imageView.setX(10);
imageView.setY(10);
imageView.setFitWidth(575);
imageView.setPreserveRatio(true);
//Setting the Scene object
Group root = new Group(imageView);
Scene scene = new Scene(root, 595, 400);
stage.setTitle("Adding Noise Example");
stage.setScene(scene);
stage.show();
}
public static void main(String args[]) {
launch(args);
}
}
ログイン後にコピー入力画像
import java.awt.Image; import java.awt.image.BufferedImage; import java.io.IOException; import javafx.application.Application; import javafx.embed.swing.SwingFXUtils; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.image.ImageView; import javafx.scene.image.WritableImage; import javafx.stage.Stage; import org.opencv.core.Core; import org.opencv.core.Mat; import org.opencv.core.MatOfDouble; import org.opencv.highgui.HighGui; import org.opencv.imgcodecs.Imgcodecs; public class AddingNoise extends Application { public void start(Stage stage) throws IOException { //Loading the OpenCV core library System.loadLibrary(Core.NATIVE_LIBRARY_NAME); //Reading the Image from the file String file ="D://images//elephant.jpg"; Mat src = Imgcodecs.imread(file); System.out.println("Image Loaded"); //Creating destination matrix Mat dst = new Mat(src.rows(), src.cols(), src.type()); //Creating a matrix for the noise Mat noise = new Mat(src.rows(), src.cols(), src.type()); //Calculating the mean and standard deviation MatOfDouble mean = new MatOfDouble(); MatOfDouble dev = new MatOfDouble(); Core.meanStdDev(src, mean, dev); //Filling the noise matrix Core.randn(noise, mean.get(0,0)[0], dev.get(0,0)[0]); //Adding noise to the destination Core.add(src, noise, dst); //Converting matrix to JavaFX writable image Image img = HighGui.toBufferedImage(dst); WritableImage writableImage= SwingFXUtils.toFXImage((BufferedImage) img, null); //Setting the image view ImageView imageView = new ImageView(writableImage); imageView.setX(10); imageView.setY(10); imageView.setFitWidth(575); imageView.setPreserveRatio(true); //Setting the Scene object Group root = new Group(imageView); Scene scene = new Scene(root, 595, 400); stage.setTitle("Adding Noise Example"); stage.setScene(scene); stage.show(); } public static void main(String args[]) { launch(args); } }
##出力
上記のプログラムを実行すると、次の出力が生成されます−
以上がJava OpenCVライブラリを使用して画像にノイズを追加するにはどうすればよいですか?の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

AI Hentai Generator
AIヘンタイを無料で生成します。

人気の記事

ホットツール

メモ帳++7.3.1
使いやすく無料のコードエディター

SublimeText3 中国語版
中国語版、とても使いやすい

ゼンドスタジオ 13.0.1
強力な PHP 統合開発環境

ドリームウィーバー CS6
ビジュアル Web 開発ツール

SublimeText3 Mac版
神レベルのコード編集ソフト(SublimeText3)

ホットトピック









Javaのクラスロードには、ブートストラップ、拡張機能、およびアプリケーションクラスローダーを備えた階層システムを使用して、クラスの読み込み、リンク、および初期化が含まれます。親の委任モデルは、コアクラスが最初にロードされ、カスタムクラスのLOAに影響を与えることを保証します

この記事では、カフェインとグアバキャッシュを使用してJavaでマルチレベルキャッシュを実装してアプリケーションのパフォーマンスを向上させています。セットアップ、統合、パフォーマンスの利点をカバーし、構成と立ち退きポリシー管理Best Pra

この記事では、キャッシュや怠zyなロードなどの高度な機能を備えたオブジェクトリレーショナルマッピングにJPAを使用することについて説明します。潜在的な落とし穴を強調しながら、パフォーマンスを最適化するためのセットアップ、エンティティマッピング、およびベストプラクティスをカバーしています。[159文字]

この記事では、Javaプロジェクト管理、自動化の構築、依存関係の解像度にMavenとGradleを使用して、アプローチと最適化戦略を比較して説明します。

この記事では、MavenやGradleなどのツールを使用して、適切なバージョン化と依存関係管理を使用して、カスタムJavaライブラリ(JARファイル)の作成と使用について説明します。
