java - implementing Discrete Wavelet Transformation on android -


i'm writing application applying discrete wavelet transformation on image , inverse class applying algorithm works in java when try convert android platform image dose not appear don't know why here code class , main activity :

wtc using haar class :

import android.graphics.bitmap;  /**  * @author the-e_000  */ public class haar {      private final double w0 = 0.5;     private final double w1 = -0.5;     private final double s0 = 0.5;     private final double s1 = 0.5;      /// <summary>     ///   discrete haar wavelet transform     /// </summary>     ///     public void fwt(double[] data) {         double[] temp = new double[data.length];          int h = data.length >> 1;         (int = 0; < h; i++) {             int k = (i << 1);             temp[i] = data[k] * s0 + data[k + 1] * s1;             temp[i + h] = data[k] * w0 + data[k + 1] * w1;         }          (int = 0; < data.length; i++)             data[i] = temp[i];     }      /// <summary>     ///   discrete haar wavelet 2d transform     /// </summary>     ///     public void fwt(double[][] data, int iterations) {         int rows = data.length;         int cols = data[0].length;         double[] row = new double[cols];         double[] col = new double[rows];         (int k = 0; k < iterations; k++) {             (int = 0; < rows; i++) {                 (int j = 0; j < row.length; j++)                     row[j] = data[i][j];                 fwt(row);                 (int j = 0; j < row.length; j++)                     data[i][j] = row[j];             }             (int j = 0; j < cols; j++) {                 (int = 0; < col.length; i++)                     col[i] = data[i][j];                 fwt(col);                 (int = 0; < col.length; i++)                     data[i][j] = col[i];             }         }     }      /// <summary>     ///   inverse haar wavelet transform     /// </summary>     ///     public void iwt(double[] data) {         double[] temp = new double[data.length];          int h = data.length >> 1;         (int = 0; < h; i++) {             int k = (i << 1);             temp[k] = (data[i] * s0 + data[i + h] * w0) / w0;             temp[k + 1] = (data[i] * s1 + data[i + h] * w1) / s0;         }          (int = 0; < data.length; i++)             data[i] = temp[i];     }      /// <summary>     ///   inverse haar wavelet 2d transform     /// </summary>     ///     public void iwt(double[][] data, int iterations) {         int rows = data.length;         int cols = data[0].length;         double[] col = new double[rows];         double[] row = new double[cols];         (int l = 0; l < iterations; l++) {             (int j = 0; j < cols; j++) {                 (int = 0; < row.length; i++)                     col[i] = data[i][j];                 iwt(col);                 (int = 0; < col.length; i++)                     data[i][j] = col[i];             }             (int = 0; < rows; i++) {                 (int j = 0; j < row.length; j++)                     row[j] = data[i][j];                 iwt(row);                 (int j = 0; j < row.length; j++)                     data[i][j] = row[j];             }         }     }      public double scale(double frommin, double frommax, double tomin, double tomax, double x) {         if (frommax - frommin == 0) {             return 0;         }         double value = (tomax - tomin) * (x - frommin) / (frommax - frommin) + tomin;         if (value > tomax) {             value = tomax;         }         if (value < tomin) {             value = tomin;         }         return value;     }      public void applyhaartransform(boolean forward, bitmap img) throws exception {          int iterations = 1;         double[][] red = new double[img.getwidth()][img.getheight()];         double[][] green = new double[img.getwidth()][img.getheight()];         double[][] blue = new double[img.getwidth()][img.getheight()];         int c;         (int j = 0; j < img.getheight(); j++) {             (int = 0; < img.getwidth(); i++) {                 c = img.getpixel(i, j);                 red[i][j] = (double) scale(0, 255, -1, 1, (c >> 16) & 0x000000ff);                 green[i][j] = (double) scale(0, 255, -1, 1, (c >> 8) & 0x000000ff);                 blue[i][j] = (double) scale(0, 255, -1, 1, (c) & 0x000000ff);             }         }         if (forward) {             fwt(red, iterations);             fwt(green, iterations);             fwt(blue, iterations);         } else {             iwt(red, iterations);             iwt(green, iterations);             iwt(blue, iterations);         }         (int j = 0; j < img.getheight(); j++) {             (int = 0; < img.getwidth(); i++) {                 int r = (int) scale(-1, 1, 0, 255, red[i][j]);// red component 0...255                 int g = (int) scale(-1, 1, 0, 255, green[i][j]);// green component 0...255                 int b = (int) scale(-1, 1, 0, 255, blue[i][j]);// blue component 0...255                 int col = (r << 16) | (g << 8) | b;                 img.setpixel(i, j, col);             }         }     } } 

main activity :

bitmap img = bitmapfactory.decodefile(imgdecodablestring); imageview imgview = (imageview) findviewbyid(r.id.imgview); // take image , add transform haar trans = new haar(); bitmap img2 = null; try {     trans.applyhaartransform(true, true, img); } catch(exception e) {     toast.maketext(this,e.getmessage(), toast.length_long).show(); } // set image in imageview after decoding string imgview.setimagebitmap(img2); 

in code u put null image in imageview:

bitmap img2 = null; 

and after transformation code

imgview.setimagebitmap(img2); 

but

try {     trans.applyhaartransform(true, true, img); } catch(exception e) {     toast.maketext(this,e.getmessage(), toast.length_long).show(); } 

have no effect on img2 instead u may make method :

public void applyhaartransform(boolean forward, bitmap img) 

returns image , is

public bitmap applyhaartransform(boolean forward, bitmap img) 

and before closing parathesis add 1 line of code :

return img; 

and in try catch code yourcode be:

try {     img2=trans.applyhaartransform(true, true, img); } catch(exception e) {     toast.maketext(this,e.getmessage(), toast.length_long).show(); } 

Comments

Popular posts from this blog

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - UML - How would you draw a try catch in a sequence diagram? -

c++ - No viable overloaded operator for references a map -