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. function soft thresholding

function soft thresholding

Scheduled Pinned Locked Moved C / C++ / MFC
question
3 Posts 3 Posters 0 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.
  • S Offline
    S Offline
    saidinsan000000000
    wrote on last edited by
    #1

    this code correct or no? thank you in advance.

    #include
    #include
    #include
    #include
    #include
    #include

    using namespace std;
    using namespace cv;
    float soft_tresholding(Mat src, float threshold)
    {

    int height=src.rows;
    int width=src.cols;
    for(int y=0; y < height; y++)
    {
    for(int x=0; x < width; x++)
    {
    if (src(y*width+x) > threshold)
    src(y*width+x) = src(y*width+x) - threshold;
    else if (src(y*width+x) < -threshold)
    src(y*width+x) = src(y*width+x) + threshold;
    else
    src(y*width+x) = 0;
    }
    }
    }
    int main()
    {
    system("clear");

    Mat src=imread("/home/jamal/Bureau/lena.jpg",0);
    Mat dst;
    float threshold;
    dst=soft_thresholding(src,threshold);

    namedWindow("Picture", CV\_WINDOW\_AUTOSIZE); 
       imshow("Picture", src); 
          namedWindow("picf", CV\_WINDOW\_AUTOSIZE); 
       imshow("Picf", dst); 
       waitKey(); 
        
    return 0;
    

    }

    V D 2 Replies Last reply
    0
    • S saidinsan000000000

      this code correct or no? thank you in advance.

      #include
      #include
      #include
      #include
      #include
      #include

      using namespace std;
      using namespace cv;
      float soft_tresholding(Mat src, float threshold)
      {

      int height=src.rows;
      int width=src.cols;
      for(int y=0; y < height; y++)
      {
      for(int x=0; x < width; x++)
      {
      if (src(y*width+x) > threshold)
      src(y*width+x) = src(y*width+x) - threshold;
      else if (src(y*width+x) < -threshold)
      src(y*width+x) = src(y*width+x) + threshold;
      else
      src(y*width+x) = 0;
      }
      }
      }
      int main()
      {
      system("clear");

      Mat src=imread("/home/jamal/Bureau/lena.jpg",0);
      Mat dst;
      float threshold;
      dst=soft_thresholding(src,threshold);

      namedWindow("Picture", CV\_WINDOW\_AUTOSIZE); 
         imshow("Picture", src); 
            namedWindow("picf", CV\_WINDOW\_AUTOSIZE); 
         imshow("Picf", dst); 
         waitKey(); 
          
      return 0;
      

      }

      V Offline
      V Offline
      Victor Nijegorodov
      wrote on last edited by
      #2

      saidinsan000000000 wrote:

      this code correct or no?

      But didn't you test it? :confused: Does it compile? Does it work as expected?

      1 Reply Last reply
      0
      • S saidinsan000000000

        this code correct or no? thank you in advance.

        #include
        #include
        #include
        #include
        #include
        #include

        using namespace std;
        using namespace cv;
        float soft_tresholding(Mat src, float threshold)
        {

        int height=src.rows;
        int width=src.cols;
        for(int y=0; y < height; y++)
        {
        for(int x=0; x < width; x++)
        {
        if (src(y*width+x) > threshold)
        src(y*width+x) = src(y*width+x) - threshold;
        else if (src(y*width+x) < -threshold)
        src(y*width+x) = src(y*width+x) + threshold;
        else
        src(y*width+x) = 0;
        }
        }
        }
        int main()
        {
        system("clear");

        Mat src=imread("/home/jamal/Bureau/lena.jpg",0);
        Mat dst;
        float threshold;
        dst=soft_thresholding(src,threshold);

        namedWindow("Picture", CV\_WINDOW\_AUTOSIZE); 
           imshow("Picture", src); 
              namedWindow("picf", CV\_WINDOW\_AUTOSIZE); 
           imshow("Picf", dst); 
           waitKey(); 
            
        return 0;
        

        }

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

        saidinsan000000000 wrote:

        this code correct or no?

        It all depends on what you mean by "correct." Are you asking if it is syntactically correct, logically correct, or some other measurement?

        "One man's wage rise is another man's price increase." - Harold Wilson

        "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

        "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

        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