Answers.Body: <p><strong>Here is what I understand you to be asking</strong></p>
  <p>Given:</p>
  <ul>
  <li>Task: is plant disease detection</li>
  <li>Solution domain: is deep learning and computer vision</li>
  <li>Tool: is <a href="https://paperswithcode.com/method/u-net" rel="nofollow noreferrer">U-net</a></li>
  <li>Activity: image segmentation</li>
  </ul>
  <p>Questions:</p>
  <ol>
  <li>Why is image masking necessary in image segmentation?</li>
  <li>What kind of masking do we need to supply to the &quot;architecture&quot;</li>
  <li>Why segment out foreground and background but not diseased section</li>
  </ol>
  <p><strong>Here is how I would engage it:</strong></p>
  <p>I sometimes like to see if this is a problem that has already been solved before solving it myself, especially if I am doing something for class.  You can &quot;stand on the shoulders of giants&quot;.  When I look online I find the following:</p>
  <ul>
  <li><a href="https://link.springer.com/chapter/10.1007/978-3-030-75015-2_2" rel="nofollow noreferrer">https://link.springer.com/chapter/10.1007/978-3-030-75015-2_2</a></li>
  <li><a href="https://medium.com/analytics-vidhya/leaf-disease-detection-using-frcnn-fff55a537634" rel="nofollow noreferrer">https://medium.com/analytics-vidhya/leaf-disease-detection-using-frcnn-fff55a537634</a></li>
  <li><a href="https://www.kaggle.com/datasets/saroz014/plant-disease/code" rel="nofollow noreferrer">https://www.kaggle.com/datasets/saroz014/plant-disease/code</a></li>
  <li><a href="https://www.sciencedirect.com/science/article/abs/pii/S1574954122000322" rel="nofollow noreferrer">https://www.sciencedirect.com/science/article/abs/pii/S1574954122000322</a></li>
  <li><a href="https://github.com/vtalreja/Segmentation_Unet_Plants" rel="nofollow noreferrer">https://github.com/vtalreja/Segmentation_Unet_Plants</a></li>
  </ul>
  <p>Numbered answers:</p>
  <ol>
  <li><p>You want the learner to only look for disease on the parts of the images that are plants and not on the parts of the images that are not plants.  Learners are both very capable and very lazy.  If they can figure out that the color of dirt is a defining difference between two pictures, then they won't look at the plants, just the dirt.  You aren't doing dirt detection, but are specifying the domain to the plant.  The learner is to lazy to figure that out.  You have to supply images where the only part you care about is taught to the learner.  As an aside, many parts of effective ML development is providing guard-rails so that the laziest solution the learner can find isn't also pathologically bad.</p>
  </li>
  <li><p>The masking depends on the tools.  In a way this is a paraphrase of &quot;<a href="https://stats.stackexchange.com/questions/tagged/missing-data?tab=Votes">missing value imputation</a>&quot; except instead trying to do a good job of filling the hole, you want to think hard and create the right kind of a hole.  The hole-filling software that I use most is the <a href="https://cran.r-project.org/web/packages/mice/mice.pdf" rel="nofollow noreferrer">R &quot;mice&quot;</a> and some of the methods there can inform some brute-force ways to mask.  My next answer has how I would start to think about masking, though I would be open to being wrong and trying other ways, and I would also have to make a test to determine that it was detecting the disease and not the mask.</p>
  </li>
  <li><p>This goes into the point that you can't be supplying the answers, or the lazy learner won't become actually capable.  If the disease is always in the image in the training data, the learner will assume it is always in any image it is supplied.  There needs to be enough of a contrast that it can find the disease on its own.  That said, there is a fun smell here: you can mask out the diseased regions, and use the same basic picture in both the &quot;true&quot; and the &quot;false&quot; category.  Some care needs to be taken that it isn't learning to detect the mask, so instead of setting it to &quot;zero&quot; you might copy-paste some other part of the plant in various window sizes. Also you might mask good plants and have them labelled as good, so that the mask isn't the differentiator.</p>
  </li>
  </ol>
  <p>U-net itself is about cross-domain image reconstruction.  If I was trying to train for presence of disease then I might use a generative-adversarial method where the true/false can be used to update the weights in the U-net.  It is more of a pix2pix-style wrapper.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-05-28T16:37:16.910Z
Answers.LastActivityDate: 2022-05-28T16:37:16.910Z
Answers.UserDisplayName: EngrStudent
Body: <p>I am using U-Net for plant disease detection. I am new to deep learning and computer vision.</p>
  <p>Currently, we are feeding the masking images generated via open cv HSV format to detect colours from the images so that the background and foreground are detected.</p>
  <p>I need to know the purpose of image masking in image segmentation using U-Net, why it is needed? What kind of masking do we need to feed to the architecture?</p>
  <p>Do we also need to target the disease part for masking?</p>
  
Tags: <deep-learning><image-processing><image-segmentation><u-net>
Title: Use of Mask in U Net for plant disease detection
UserDisplayName: emcsquare
ThreadText: # Use of Mask in U Net for plant disease detection
  
  (Asked by: username_0 on 2022-05-28)
  
  I am using U-Net for plant disease detection. I am new to deep learning and computer vision.
  
  Currently, we are feeding the masking images generated via open cv HSV format to detect colours from the images so that the background and foreground are detected.
  
  I need to know the purpose of image masking in image segmentation using U-Net, why it is needed? What kind of masking do we need to feed to the architecture?
  
  Do we also need to target the disease part for masking?
  
  **Tags:** deep-learning, image-processing, image-segmentation, u-net
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2022-05-28. Score: 1
  
  **Here is what I understand you to be asking**
  
  Given:
  
  * Task: is plant disease detection
  * Solution domain: is deep learning and computer vision
  * Tool: is [U-net](https://paperswithcode.com/method/u-net)
  * Activity: image segmentation
  
  Questions:
  
  1. Why is image masking necessary in image segmentation?
  2. What kind of masking do we need to supply to the "architecture"
  3. Why segment out foreground and background but not diseased section
  
  **Here is how I would engage it:**
  
  I sometimes like to see if this is a problem that has already been solved before solving it myself, especially if I am doing something for class. You can "stand on the shoulders of giants". When I look online I find the following:
  
  * <https://link.springer.com/chapter/10.1007/978-3-030-75015-2_2>
  * <https://medium.com/analytics-vidhya/leaf-disease-detection-using-frcnn-fff55a537634>
  * <https://www.kaggle.com/datasets/saroz014/plant-disease/code>
  * <https://www.sciencedirect.com/science/article/abs/pii/S1574954122000322>
  * <https://github.com/vtalreja/Segmentation_Unet_Plants>
  
  Numbered answers:
  
  1. You want the learner to only look for disease on the parts of the images that are plants and not on the parts of the images that are not plants. Learners are both very capable and very lazy. If they can figure out that the color of dirt is a defining difference between two pictures, then they won't look at the plants, just the dirt. You aren't doing dirt detection, but are specifying the domain to the plant. The learner is to lazy to figure that out. You have to supply images where the only part you care about is taught to the learner. As an aside, many parts of effective ML development is providing guard-rails so that the laziest solution the learner can find isn't also pathologically bad.
  2. The masking depends on the tools. In a way this is a paraphrase of "[missing value imputation](https://stats.stackexchange.com/questions/tagged/missing-data?tab=Votes)" except instead trying to do a good job of filling the hole, you want to think hard and create the right kind of a hole. The hole-filling software that I use most is the [R "mice"](https://cran.r-project.org/web/packages/mice/mice.pdf) and some of the methods there can inform some brute-force ways to mask. My next answer has how I would start to think about masking, though I would be open to being wrong and trying other ways, and I would also have to make a test to determine that it was detecting the disease and not the mask.
  3. This goes into the point that you can't be supplying the answers, or the lazy learner won't become actually capable. If the disease is always in the image in the training data, the learner will assume it is always in any image it is supplied. There needs to be enough of a contrast that it can find the disease on its own. That said, there is a fun smell here: you can mask out the diseased regions, and use the same basic picture in both the "true" and the "false" category. Some care needs to be taken that it isn't learning to detect the mask, so instead of setting it to "zero" you might copy-paste some other part of the plant in various window sizes. Also you might mask good plants and have them labelled as good, so that the mask isn't the differentiator.
  
  U-net itself is about cross-domain image reconstruction. If I was trying to train for presence of disease then I might use a generative-adversarial method where the true/false can be used to update the weights in the U-net. It is more of a pix2pix-style wrapper.
  
  
  ---
  
  