# U5L8 Level 4 Choice B Emboss Filter

**URL:** <https://forum.code.org/t/u5l8-level-4-choice-b-emboss-filter/40382>\
**Category:** Coding and Debugging Help\
**Created:** [February 5, 2025, 5:36pm UTC](https://forum.code.org/t/u5l8-level-4-choice-b-emboss-filter/40382 "2025-02-05T17:36:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![michael.fiscus](https://avatars.discourse-cdn.com/v4/letter/m/898d66/32.png) [@michael.fiscus](https://forum.code.org/u/michael.fiscus)\
**Post date:** [February 5, 2025, 5:36pm UTC](https://forum.code.org/t/u5l8-level-4-choice-b-emboss-filter/40382/1 "2025-02-05T17:36:25Z")

</div>

My student has code that seems fine to me, but the tests fail and state that the R, G, and B values are 1 or 2 pixels low. Can anyone figure out the problem?

> **[New Java Lab Project - Code.org](https://studio.code.org/projects/javalab/G-brvRGo3Y_tMDsDq_MqdYkIwjGl3JYs2qKtdCNT0iM)**
>
> Anyone can learn computer science. Make games, apps and art with code.

---

<div class="post-metadata">

**Author:** ![sam\_stafford](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/sam_stafford/32/7651_2.png) [@sam\_stafford](https://forum.code.org/u/sam_stafford)\
**Post date:** [February 6, 2025, 2:33am UTC](https://forum.code.org/t/u5l8-level-4-choice-b-emboss-filter/40382/2 "2025-02-06T02:33:46Z")

</div>

Hi @michael.fiscus, Thank you for bringing your question to the forum. I’m trying to get to the bottom of the issue. I think I have it narrowed down to when your student puts all of the differences in an int array and then traverses it. I can’t quite say what the exact issue is, but when I put each difference in the if-else if statement the algorithm works:

```auto
Pixel[][] pixels = getPixelsFromImage();
    for (int row = 1; row < pixels.length; row++) {
      for (int col = 1; col < pixels[0].length; col++) {
        Pixel currentPixel = pixels[row][col];
        Pixel topLeft = pixels[row - 1][col - 1];

        int tempR = Math.abs(currentPixel.getRed() - topLeft.getRed());
        int tempG = Math.abs(currentPixel.getGreen() - topLeft.getGreen());
        int tempB = Math.abs(currentPixel.getBlue() - topLeft.getBlue());

        int maxDiff = 0;
        
        if(tempR > tempG && tempR > tempB){
          maxDiff = tempR;
        }
        else if(tempG > tempR && tempG > tempB){
          maxDiff = tempG;
        }
        else{
          maxDiff = tempB;
        }
        
        // int[] temp = {tempR, tempG, tempB};

        // int maxDiff = 0;
        // for (int t : temp) {
        // if (t > maxDiff) {
        // maxDiff = t;
        // }
        // }
      
        maxDiff += 128;
        
        currentPixel.setRed(maxDiff);
        currentPixel.setGreen(maxDiff);
        currentPixel.setBlue(maxDiff);

      }
    }

```

You can see that I commented out the array portion and substituted the if-else if statement which works. I’ll keep playing with it and try to determine why the enhanced for-loop isn’t working.

---

<div class="post-metadata">

**Author:** ![lindsay.davis](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/lindsay.davis/32/7632_2.png) [@lindsay.davis](https://forum.code.org/u/lindsay.davis)\
**Post date:** [February 10, 2025, 6:32pm UTC](https://forum.code.org/t/u5l8-level-4-choice-b-emboss-filter/40382/3 "2025-02-10T18:32:10Z")

</div>

Hi @michael.fiscus and @sam_stafford ,  
I dug into this and I think I found the issue. Michael, I believe your student’s code works as the algorithm was intended, and the answer key, and tests have an issue- frustrating, I know, but you can share with your student that they completed the level correctly! I will contact [support@code.org](mailto:support@code.org) about fixing this level.

Here is what I did.  
I uncommented the enhanced for loop part and gave it a different variable name to find the maximum difference, maxDiff2. I then added a print statement to see what was different and where.

 ![image](https://us1.discourse-cdn.com/flex016/uploads/codeorgforum/original/2X/d/da97253ea9b026df133520aa0411a8fa5d6a2b3b.png)  
This gave me console output that looked like this:  
 ![image](https://us1.discourse-cdn.com/flex016/uploads/codeorgforum/original/2X/2/26938ccfe5725c759e1a2f915ce8efb59f3709d8.png)

I noticed that maxDiff2 was always bigger than maxDiff when they didn’t match. Since we are looking for the maximum value out of the 3 that made me realize your student’s code was finding the bigger number and the answer key was not always finding the bigger number.  
The problem with the answer key’s algorithm for finding the biggest number is when tempR and tempG are the same, and bigger than tempB. for example if :  
tempR = 200  
tempG = 200  
tempB = 50  
The if else statements in the initial code don’t work when there are duplicates because it uses the strictly greater than symbol \>  
since 200 is not \> 200 the else will store the 50 in maxDiff, which is not the intent of the algorithm.  
I changed the \> to \>= in each of the if else if conditions and the maxDiff and maxDiff2 values always matched.  
Here is the code I used to wrap my head around this answer key issue:

> **[New Java Lab Project - Code.org](https://studio.code.org/projects/javalab/imk2FPnUyfD2HRfTFi8pkRXESZpQ8nuOQfTXDHfkmUU)**
>
> Anyone can learn computer science. Make games, apps and art with code.

Thank you, Michael for sharing your student’s code! I will alert the Code team about this issue.  
Best,  
Lindsay

---

<div class="post-metadata">

**Author:** ![michael.fiscus](https://avatars.discourse-cdn.com/v4/letter/m/898d66/32.png) [@michael.fiscus](https://forum.code.org/u/michael.fiscus)\
**Post date:** [February 10, 2025, 7:49pm UTC](https://forum.code.org/t/u5l8-level-4-choice-b-emboss-filter/40382/4 "2025-02-10T19:49:00Z")

</div>

Thanks for your work to figure this out! It seems obvious now that you have explained it. Your strategy for discovering the problem is awesome, and I will share it with my class!
