Distorted size of image obtained after construction from byte value? [closed]

asked 2018-05-04 01:17:08 -0600

Ann162 gravatar image

updated 2018-05-04 04:04:18 -0600

I am using

Mat img = new Mat(440, 442, CvType.CV_8UC1); img.put(0, 0, bytearray);

To construct back a grayscale image of 440*442 dimension after performing few conversion function on its pixel value.The obtained image has a change in its bit Depth which is 24 in the original image and 8 in the constructed image. The reconstructed image is below::::::: image description

The original image::::::: image description

edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by sturkmen
close date 2020-12-01 19:23:49.506736

Comments

"The obtained image has a change in its bit Depth which is 24 in the original image and 8 in the constructed image." -- you'll have to explain that.

berak gravatar imageberak ( 2018-05-04 03:28:39 -0600 )edit

i had a look into image properties details in which both the images has same high and width but the bit depth value is different .

Ann162 gravatar imageAnn162 ( 2018-05-04 04:01:52 -0600 )edit

the original image looks like grayscale, but is bgr, so you have to adjust your flags / processing there.

but we cannot help, until we see, what you're doing with it, and what assumptions about it are in your code

berak gravatar imageberak ( 2018-05-04 04:21:02 -0600 )edit

I am extracting 8 bit binary value of each pixel and then applying random bit function to it and then changing it to byte array to reconstruct the image

Ann162 gravatar imageAnn162 ( 2018-05-04 04:47:40 -0600 )edit

maybe you should use opencv functions all the way down, not insist on manually working on byte arrays

and again, if your input img has 3 channels, you'll have to adapt your algirithm, and the output type (or convert it to single channel before)

berak gravatar imageberak ( 2018-05-04 04:51:20 -0600 )edit

Can you give me an example as to how to make 3 channel conversion to single channel?

Ann162 gravatar imageAnn162 ( 2018-05-04 06:37:35 -0600 )edit

cvtColor(src,dst,COLOR_BGR2GRAY)

berak gravatar imageberak ( 2018-05-04 06:38:32 -0600 )edit

Now the image has changed into 8 bit depth still the same image is reconstructed.. Also when i am using Highgui.imdecode(new MatOfByte(original_pixels),Highgui.IMREAD_GRAYSCALE ) the original image is constructed perfectly from the unaltered pixel value but when applied to altered pixel value it doesn't work and gives error.

Ann162 gravatar imageAnn162 ( 2018-05-04 07:28:09 -0600 )edit

again, there is a big, black information hole around your processing, the need of byte arrays, etc.

please understand, that we cannot help with what we cannot see..

berak gravatar imageberak ( 2018-05-04 07:32:19 -0600 )edit

//1. Convert Image to byte code ImgDemo im = new ImgDemo(); String path = "C:\Users\domin\Desktop\Sop\peppers.png"; byte[] aa = im.ByteConvert(path); //System.out.println(Arrays.toString(aa));

    //2. Convert to 8 dig
    String[] ss = new String[aa.length];
    for (int i = 0; i < aa.length; i++) {
        byte b1 = (byte) aa[i];
        String s1 = String.format("%8s", Integer.toBinaryString(b1 & 0xFF)).replace(' ', '0');
        stringarray[i] = s1;

            //3. Replace 0 with *
    NumberPadding np = new NumberPadding();
    ss=np.ReplaceChar(ss);
    //System.out.println(Arrays.toString(ss));

    //4. Random number
    RandomNum an= new RandomNum();
    ss=an.GenRandom(ss);

After the 4th step the array of bytes that i get is the one i am tryng to convert to image

Ann162 gravatar imageAnn162 ( 2018-05-04 10:39:52 -0600 )edit