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

im2col function has a issue #1847

Open
thewq opened this issue Apr 10, 2020 · 3 comments
Open

im2col function has a issue #1847

thewq opened this issue Apr 10, 2020 · 3 comments

Comments

@thewq
Copy link

@thewq thewq commented Apr 10, 2020

def im2col(image, block_size):
    rows, cols = image.shape
    dst_height = cols - block_size[1] + 1
    dst_width = rows - block_size[0] + 1
    image_array = zeros((dst_height * dst_width, block_size[1] * block_size[0]))
    row = 0
    for i in range(0, dst_height):
        for j in range(0, dst_width):
            window = ravel(image[i : i + block_size[0], j : j + block_size[1]])
            image_array[row, :] = window
            row += 1
    return image_array`
```
**### #There should be:
    for i in range(0, dst_width):
        for j in range(0, dst_height):**
@itsvinayak
Copy link
Member

@itsvinayak itsvinayak commented Apr 24, 2020

def im2col(image, block_size):
    rows, cols = image.shape
    dst_height = cols - block_size[1] + 1
    dst_width = rows - block_size[0] + 1
    image_array = zeros((dst_height * dst_width, block_size[1] * block_size[0]))
    row = 0
    for i in range(0, dst_height):
        for j in range(0, dst_width):
            window = ravel(image[i : i + block_size[0], j : j + block_size[1]])
            image_array[row, :] = window
            row += 1
    return image_array`

### #There should be:
for i in range(0, dst_width):
for j in range(0, dst_height):

@thewq please explain the issue, provide some details

@TheAlgorithms TheAlgorithms deleted a comment from Togrul2001 Apr 24, 2020
@cclauss
Copy link
Member

@cclauss cclauss commented Apr 24, 2020

What is the outer loop and what is the inner loop? height / width or width / height?

While in this code, I would replace i and j with h and w (or w and h).

@ken437
Copy link
Contributor

@ken437 ken437 commented May 16, 2020

Is there a situation where this function gives an incorrect result or crashes?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.