Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Things aren't working and I'm stuck! #20

Closed
2 tasks done
lottagambert opened this issue Jan 31, 2025 · 2 comments
Closed
2 tasks done

Things aren't working and I'm stuck! #20

lottagambert opened this issue Jan 31, 2025 · 2 comments
Labels
help wanted Things aren't working and I'm stuck! WS 24/25

Comments

@lottagambert
Copy link

Repository

https://github.com/lottagambert/mobi-fs3-python

Access rights

  • I hereby confirm that the supervisors can access my GitHub repository.

Git commit and push

  • I hereby confirm that I have committed and pushed to my GitHub repository.

Task

Task 2.3.2

Describe the problem (if possible)

Image is not clipped although code runs without errors

@lottagambert lottagambert added the help wanted Things aren't working and I'm stuck! label Jan 31, 2025
@kostrykin
Copy link
Member

kostrykin commented Jan 31, 2025

The issue is probably due to the following, luckily spotted by my colleague @Renpeng007, thanks.

Your code has the following structure:

x = 0
y = 0
img_clip = img.copy()

while y < img.shape[0]:

    while x < img.shape[1]:

        ...
 
        x = x + 1

    y = y + 1

The ... part is supposed to be executed for each pair of coordinates x and y. Those are initialized with 0 in line 1 and 2, which is correct. But let's see, what happens after finishing the first row of pixels? In that case, when the ... part is executed, x is the last column and y is 0. Then, x is incremented by 1, and the inner loop terminates, because x < img.shape[1] is no longer true. Then, y is incremented by 1, so the processing of the second row of pixels begins. However, we still have x referring to the last column plus 1! So in the next iteration of the outer loop, the condition x < img.shape[1] of the inner loop is still false, so the second row is never actually processed, and neither is the third, or any other row of pixels after the first.

The mistake that we have made is that we haven't reset x to 0 after finishing the first row! Lets fix that:

x = 0
y = 0
img_clip = img.copy()
while y < img.shape[0]:

    while x < img.shape[1]:

        i = img[y, x]
        if i < T1: 
            img_clip[y, x] = T1
            
        elif i > T2:
            img_clip[y, x] = T2 

        x = x + 1

    y = y + 1
    x = 0

This code should work (I have only added the instruction x = 0 at the bottom, you can also find the fully fixed version of your code here). Please report back whether the issue is fixed now. @lottagambert

@lottagambert
Copy link
Author

lottagambert commented Feb 1, 2025 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Things aren't working and I'm stuck! WS 24/25
Projects
None yet
Development

No branches or pull requests

2 participants