スキップしてメイン コンテンツに移動

投稿

ラベル(Image Processing)が付いた投稿を表示しています

Java: Create Indexed PNG Image Using Standard Java Image API

Hello guys! I have written Java: How to Create Indexed PNG Using PNGJ Library a few years ago. Recently I investigated how to create indexed png by standard Java image API. I have googled and tested various methods, finally I figureed out how to create indexed png image. Still my program is not perfect (of course most of the case it worked well), I believe that this program gives you the hint to creating indexed png and image manipulation on standard Java API. Code Actually the method is quite straigt forward. Please see the code below :) The advantedge of this code is the code doesn't require any library. The code below contains all of the stuffs needed for creating indexed png image! package com.dukesoftware.util.image; import java.awt.color.ColorSpace; import java.awt.image.BufferedImage; import java.awt.image.ColorConvertOp; import java.awt.image.ColorModel; import java.awt.image.DataBuffer; import java.awt.image.IndexColorModel; import java.io.File; import java.

Java: How to Manipulate Image as Double Array (Read and Write)

Read Image as Double Array You might think "We can use Raster#getPixel method if we would like to grab pixels, can't we?". Yes that's true. The key problem is the low performance because getPixel method internally call SampleModel and convert raw value to proper pixel value every method call. So we should call Raster#getPixels method and grab all pixels one method call. I have done similar stuffs in C# and posted on this blog. On the other hand in Java, this is a bit messy because there are a lot of related classes - Raster, ImageIO, Reader, Writer, etc ;). The simplest way I did is: read image as BufferedImage by ImageIO call BufferedImage#getRaster method call Raster#getPixels method Here is an exmple code. public static TemporalImage readImagePixelDoubleArray(InputStream is, int bitPerPixel) throws IOException{ BufferedImage image = ImageIO.read(is); Raster raster = image.getRaster(); int x = raster.getMinX(); int y = raster.

Java: How to Create Indexed PNG Using PNGJ Library

I'm working on Google App Engine for Java (GAEJ) now. Very excited about working on it because can develop Java Web App quite easliy & quickly! However I faced a limitation of image processing on GAEJ. On GAEJ, java.awt pakage.* is not supported. That means we cannot use BufferedImage etc!! As you know, Google provides com.google.appengine.api.images.* for image processing on GAEJ, something like below: ImagesService imagesService = ImagesServiceFactory.getImagesService(); Image srcImage = ImagesServiceFactory.makeImage(srcImageData); // some transformations. Transform crop = ImagesServiceFactory.makeCrop(0.3, 0, 1, 0.70); OutputSettings settings = new OutputSettings(OutputEncoding.PNG); // apply transform Image newImage = imagesService.applyTransform(crop, srcImage, settings); byte[] newImageData = newImage.getImageData(); It can read jpg, png, gif images accroding to the official document. And if transformation is applied, the output binary data becomes png forma

C#: How to Read Image as Double Array (for Image Processing)

As you know I am really interested in image processing. For my first step, I wrote the program for reading image as double array in C#. The code is imperfect but I think this will help someone's understand.... Here is an example usage. var original = Bitmap.FromFile(@"C:\temp\test.jpg"); double[,] values = new Bitmap(original).To2DimDoubleArray(); // image processing part! // let's do something fun :D - filtering, binalizing, etc. // for now, removing R value from the image. for (int i = 0, len = values.Length/values.GetLength(0); i < len; i++ ) { //values[0, i] = 0; // a values[1, i] = 0; // r //values[2, i] = 0; // g //values[3, i] = 0; // b } values .ToBitmap(original.Width, original.Height, PixelFormat.Format32bppArgb) .SaveImageAsJpeg(@"c:\temp\test2.jpg", 75); The image processing result of above example program. The left image is original, the right image is the result image which is red value is removed.

画像処理プログラミングでお勧めの本

私が読んだ画像処理の書籍の中でお勧めできるものをご紹介します。 詳解 画像処理プログラミング 基本的な処理は網羅されています。解説は丁寧で非常に分かりやすいです。特にサンプルプログラムが豊富なので、私のようなDeveloper型(?)の人間にとっても楽しく読めます。残念なのは、掲載されている画像がモノカラーな点と、誤字・脱字が多いことでしょうか。 ディジタル画像処理 画像処理に関する内容が広範に掲載されており、画像処理全体を概観するのに非常に役立ちます。オールカラーなので処理結果を理解しやすいです。今まで読んだ画像処理系の本の中では一番お勧めです! Learning OpenCV この本は分量も多くOpenCVのAPI解説だけにとどまらず、画像処理の理論的背景が非常に詳しく解説されています。お勧めです。 以下の本はちゃんと読んでいませんが、役に立ちそう、面白そうだと思う本です。 詳解 圧縮処理プログラミング 上のリンクからサンプルプログラムもダウンロードできます。

Javascript + HTML5を使った画像処理

HTML5のcanvasエレメントを使うと画像のピクセル処理ができると知りまして、試しにJavascriptで画像処理プログラムを書いてみました。 「画像処理なんてServer Sideでやれよ!」とか「なんでC++ではなくてJavascript?」というご指摘もありそうですがご容赦のほどを。 デモを公開 しました。 注意点など   デモを見るにはHTML5対応のブラウザが必要(当たり前)。  サイズの大きなメディアンフィルタのデモは少し時間がかかるので、気長に待ってください。  サーバサイド側では何もしていません。興味のある方はhtmlのソースを見てください。役に立ちそうなら、勝手に使っちゃってください。(でもこのブログにリンクとか張ってくれると、とても嬉しいです。)  今のところ以下の処理が選択できます。がんばって増やします!! 輝度変換 グレースケール化(YUV画像ののY値信号のみ取り出し) メディアンフィルタ(3x3, 5x5, 7x7) 判別分析法による2値化 Prewitt Filter Sobel Filter Laplacian Filter Sharpening Filter LOG Filter(エッジ検出)  今後、試したい処理 Gammaカーブ変更 コーナー検出 ハフ変換 パターンマッチング アフィン変換 画像のResampling フーリエ変換 バイラテラルフィルタ ラベリング ソースコード例 上記のURLからソースコードを読むと余計なコードが入っていますので、純粋に画像処理部分だけ抜き出したコードを下に示します。 興味がある方は、サンプルサイトのソースコードを読んでみてください。 判別分析法による2値化 function binalyze(srcRgbImageData, destImageData) { var step = 4; var LEN = 256, MAX=255; var srcRgb = srcRgbImageData.data; var dest = destImageData.data; var imgWidth = srcRgbImageData.width; v

JavaでCMYK Color SpaceのJPEGを読み込む

Read CMYK JPEG Image CMYKのJPEG画像をJavaで読む方法ではまったので、Google先生で色々調べて見ました。 Problem reading JPEG image using ImageIO.read(File file) によるとImageIOで読めないJPEGファイルはほとんどCMYK Color Spaceの画像のようです。 私の場合もまず読めないJPEGがあることでCMYKのJPEGであることに気がつきました。 という訳で、CMYKのJPEGをどうやって読み込めばいいのということで色々調べてみました。 以下のstackoverflowによると、基本的にまずCMYKのColor Spaceで読み込んで、それからRGB系のColor Spaceに変換することでJavaでも読み込みができるようです。 Pure Java alternative to JAI ImageIO for detecting CMYK images How do I convert images between CMYK and RGB in ColdFusion (Java)? How to convert from CMYK to RGB in Java correctly? ただし、このCMYKのColor Spaceインスタンスを作るのが結構面倒です。 前述のstackoverflowによると、以下の方法があるようです。 CMYKのColorSpaceをSanselanライブラリを使って画像から抜き出す ICC_Profile iccProfile = Sanselan.getICCProfile(new File("filename.jpg")); ColorSpace cs = new ICC_ColorSpace(iccProfile); 自分でCMYKColorSpaceクラスを定義して、インスタンス化する iccプロファイルから、ColorSpaceインスタンスを生成する。ただしiccプロファイルはどこかから自前に用意する必要があります。 ICC_Profile iccProfileCYMK = ICC_Profile.getInstance(new FileInputStre