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

Support slicewise assignment. #21

Closed
gvwilson opened this issue Jul 30, 2013 · 9 comments
Closed

Support slicewise assignment. #21

gvwilson opened this issue Jul 30, 2013 · 9 comments

Comments

@gvwilson
Copy link

The following code doesn't work:

grid = ImageGrid(4, 4)
grid[0:2, 0:2] = grid[1:3, 1:3]

We would like it to for teaching purposes. We would also like:

grid[0:2, 0:2].red = 128

and similar.

@jiffyclub
Copy link
Owner

First item fixed in #23. Second shouldn't be too hard to add either with a property setter. The one thing I worry about there is that grid[:2, :2].red, etc. will be odd birds in the sense that they will only exist as setters, trying to get those attributes will raise exceptions.

@gvwilson
Copy link
Author

gvwilson commented Aug 1, 2013

On 2013-08-01 3:59 PM, Matt Davis wrote:

First item fixed in #23
#23. Second
shouldn't be too hard to add either with a property setter. The one
thing I worry about there is that |grid[:2, :2].red|, etc. will be odd
birds in the sense that they will only exist as setters, trying to
/get/ those attributes will raise exceptions.

Why will they only exist as setters? I think it makes sense to say:

grid[:, :].red = other_grid[:, :].green

or

grid[:, :].red = grid[:, :].red / 2

@jiffyclub
Copy link
Owner

Hmm, your first example maybe, if we think of grid[:, :].green as a nested list of integers.

But that won't work with your second example unless we bring numpy into the picture.

@gvwilson
Copy link
Author

gvwilson commented Aug 1, 2013

On 2013-08-01 5:44 PM, Matt Davis wrote:

Hmm, your first example maybe, if we think of |grid[:, :].green| as a
nested list of integers.

But that won't work with your second example unless we bring numpy
into the picture.

Let's ticket it, and I'll try to find a volunteer to work on it? We had
a few respond to our call on Twitter...
Thx,
G

@jiffyclub
Copy link
Owner

And I should have said that bringing numpy into the picture is not an option. I'm keeping this dependency free.

I've mentally sketched out how to implement this, I think I should be able to get it done in an hour here sometime.

@jiffyclub
Copy link
Owner

Actually, grid.red could be a new BlockGrid with the red and green channels set to zero... (Or we could add gray-scale support). We'd have to implement __div__ on BlockGrid to support the math, but that could be done. That has some interesting parallels to PIL and making RGB images by merging three layers.

@jiffyclub
Copy link
Owner

Thinking about this a bit more going the route of monochrome grids seems like the thing to do. If we just use nested lists then indexing won't match for ImageGrid.

@jiffyclub
Copy link
Owner

Okay:

If I get a chance I'd like to do these myself, but no promises on timeliness.

@jiffyclub
Copy link
Owner

Grid to grid assignment added in #23.

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

No branches or pull requests

2 participants