Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. how to do this code?

how to do this code?

Scheduled Pinned Locked Moved C / C++ / MFC
data-structureshelptutorialquestion
5 Posts 3 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    gentleguy
    wrote on last edited by
    #1

    dear all how to do the following code, i spent much time, however i couldn't complete it, thanks a lot. for (int iY=0,iX=0;iY { if (iY==0) ucImgdata[iX]=ucImgdata[iX]*mask[1]+ucImgdata[iX+1]*mask[2]; else if (iY==iHeight-1) ucImgdata[iX]=ucImgdata[iX]*mask[0]+ucImgdata[iX+1]*mask[1]; else ucImgdata[iX]=ucImgdata[iX]*mask[0]+ucImgdata[iX+1]*mask[1]+ucImgdata[iX+2]*mask[2]; } ucImgdata+=iBuffwidth; actually my goal is i have two arrays, one is 1x3, the other is iWidth x iHeight,first i want to multiply every point of iWidth x iHeight by center point of 1x3, when first point or last point of 1x3 array is out of iWidth x iHeight, just don't evaluate.that means i multiply each point of iWidth x iHeight by center point of 1x3 from beginning to end. however i tried to do this, but couldn't, the code above is no problem when i compiled, but when i processed the image via invoking this function, it aborted, thanks a lot

    Li Zhiyuan

    U D 2 Replies Last reply
    0
    • G gentleguy

      dear all how to do the following code, i spent much time, however i couldn't complete it, thanks a lot. for (int iY=0,iX=0;iY { if (iY==0) ucImgdata[iX]=ucImgdata[iX]*mask[1]+ucImgdata[iX+1]*mask[2]; else if (iY==iHeight-1) ucImgdata[iX]=ucImgdata[iX]*mask[0]+ucImgdata[iX+1]*mask[1]; else ucImgdata[iX]=ucImgdata[iX]*mask[0]+ucImgdata[iX+1]*mask[1]+ucImgdata[iX+2]*mask[2]; } ucImgdata+=iBuffwidth; actually my goal is i have two arrays, one is 1x3, the other is iWidth x iHeight,first i want to multiply every point of iWidth x iHeight by center point of 1x3, when first point or last point of 1x3 array is out of iWidth x iHeight, just don't evaluate.that means i multiply each point of iWidth x iHeight by center point of 1x3 from beginning to end. however i tried to do this, but couldn't, the code above is no problem when i compiled, but when i processed the image via invoking this function, it aborted, thanks a lot

      Li Zhiyuan

      U Offline
      U Offline
      uusheikh
      wrote on last edited by
      #2

      Hi, if i get what you're saying, you are trying to a convolution on the image. You have a convolution kernel of [3x1] ( width is 3, height is 1) and an image of [height x width]. I'll assume your image is an 8-bit per pixel image (Grayscale). You can achieve convolution by; unsigned char kernel[3] = {1,3,1}; // kernel values (example) unsigned char *pImage = XXX; // pointer to the image for(int y = 0; y < height; y++) for(int x = 1; x < width-1; x++) // start from 2nd pixel, and stop 1 before width becoz of kernel size { pImage[x+y*width] = pImage[(x-1)+y*width]*kernel[0] + pImage[x+y*width]*kernel[1] + pImage[(x+1)+y*width]*kernel[2]; } Also note, the result might be bigger than the capacity of unsigned char (in this example), so it is advisable to divide the convolution result by the kernel total size, that is (1+3+1) = 5 in this case. (Not shown above). If you want to maintain the result without dividing, the output image size must be bigger, like 'int' etc. Hope this helps. Before i forget, the kernel i used is [3x1], you can also do [1x3] vertical kernel, just change the x,y operation above. Cheers

      G 1 Reply Last reply
      0
      • U uusheikh

        Hi, if i get what you're saying, you are trying to a convolution on the image. You have a convolution kernel of [3x1] ( width is 3, height is 1) and an image of [height x width]. I'll assume your image is an 8-bit per pixel image (Grayscale). You can achieve convolution by; unsigned char kernel[3] = {1,3,1}; // kernel values (example) unsigned char *pImage = XXX; // pointer to the image for(int y = 0; y < height; y++) for(int x = 1; x < width-1; x++) // start from 2nd pixel, and stop 1 before width becoz of kernel size { pImage[x+y*width] = pImage[(x-1)+y*width]*kernel[0] + pImage[x+y*width]*kernel[1] + pImage[(x+1)+y*width]*kernel[2]; } Also note, the result might be bigger than the capacity of unsigned char (in this example), so it is advisable to divide the convolution result by the kernel total size, that is (1+3+1) = 5 in this case. (Not shown above). If you want to maintain the result without dividing, the output image size must be bigger, like 'int' etc. Hope this helps. Before i forget, the kernel i used is [3x1], you can also do [1x3] vertical kernel, just change the x,y operation above. Cheers

        G Offline
        G Offline
        gentleguy
        wrote on last edited by
        #3

        thanks friend, my kernel is also 3x1, i made a mistake. thanks a lot, first let me try to do, if any problem, hope you can continue helping me.thanks freind, i need to do twice convolution, first time is 1x3, sencond is 3x1, by i have to multiply each point of image, i read your code, you started from second pixel of image, my boss asked me to start from first pixel. how to carry out twice convolution? first 1x3, and then 3x1, thanks a lot

        Li Zhiyuan

        modified on Tuesday, March 4, 2008 1:56 AM

        G 1 Reply Last reply
        0
        • G gentleguy

          thanks friend, my kernel is also 3x1, i made a mistake. thanks a lot, first let me try to do, if any problem, hope you can continue helping me.thanks freind, i need to do twice convolution, first time is 1x3, sencond is 3x1, by i have to multiply each point of image, i read your code, you started from second pixel of image, my boss asked me to start from first pixel. how to carry out twice convolution? first 1x3, and then 3x1, thanks a lot

          Li Zhiyuan

          modified on Tuesday, March 4, 2008 1:56 AM

          G Offline
          G Offline
          gentleguy
          wrote on last edited by
          #4

          dear friend how to code using 3x1, i can do using 1x3, now because i used rgb to do this, so i have width*3, how to change rgb three values to one grayscale value? thanks a lot

          Li Zhiyuan

          modified on Tuesday, March 4, 2008 4:06 AM

          1 Reply Last reply
          0
          • G gentleguy

            dear all how to do the following code, i spent much time, however i couldn't complete it, thanks a lot. for (int iY=0,iX=0;iY { if (iY==0) ucImgdata[iX]=ucImgdata[iX]*mask[1]+ucImgdata[iX+1]*mask[2]; else if (iY==iHeight-1) ucImgdata[iX]=ucImgdata[iX]*mask[0]+ucImgdata[iX+1]*mask[1]; else ucImgdata[iX]=ucImgdata[iX]*mask[0]+ucImgdata[iX+1]*mask[1]+ucImgdata[iX+2]*mask[2]; } ucImgdata+=iBuffwidth; actually my goal is i have two arrays, one is 1x3, the other is iWidth x iHeight,first i want to multiply every point of iWidth x iHeight by center point of 1x3, when first point or last point of 1x3 array is out of iWidth x iHeight, just don't evaluate.that means i multiply each point of iWidth x iHeight by center point of 1x3 from beginning to end. however i tried to do this, but couldn't, the code above is no problem when i compiled, but when i processed the image via invoking this function, it aborted, thanks a lot

            Li Zhiyuan

            D Offline
            D Offline
            David Crow
            wrote on last edited by
            #5

            Step through the code using the debugger.

            "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

            "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups