Skip to content

Commit 076f3d4

Browse files
authored
Merge pull request #210 from quist00/pr/useRYandCX
proposed compromise for issue #78
2 parents 7647156 + cafb0fa commit 076f3d4

File tree

5 files changed

+43
-37
lines changed

5 files changed

+43
-37
lines changed

_episodes/02-image-basics.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ keypoints:
1919
- "Digital images are represented as rectangular arrays of square pixels."
2020
- "Digital images use a left-hand coordinate system, with the origin in the
2121
upper left corner, the x-axis running to the right, and the y-axis running
22-
down."
22+
down. Some learners may prefer to think in terms of counting down rows
23+
for the y-axis and across columns for the x-axis. Thus, we will make an
24+
effort to allow for both approaches in our lesson presentation."
2325
- "Most frequently, digital images use an additive RGB model, with eight bits
2426
for the red, green, and blue channels."
2527
- "skimage images are stored as multi-dimensional NumPy arrays."
@@ -288,7 +290,11 @@ print(zero)
288290
> Until you have worked with images for a while,
289291
> the most common mistake that you will make with coordinates is to forget
290292
> that y coordinates get larger as they go down instead of up
291-
> as in a normal Cartesian coordinate system.
293+
> as in a normal Cartesian coordinate system. Consequently, it may be helpful to think
294+
> in terms of counting down rows (r) for the y-axis and across columns (c) for the x-axis. This
295+
> can be especially helpful in cases where you need to transpose image viewer data
296+
> provided in *x,y* format to *y,x* format. Thus, we will use *cx* and *ry* where appropriate
297+
> to help bridge these two approaches.
292298
{: .callout }
293299
294300
> ## Changing Pixel Values (5 min)

_episodes/03-skimage-images.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ In this case, the `.tif` extension causes the image to be saved as a TIFF.
178178
> Don't forget to use `fig, ax = plt.subplots()` so you don't overwrite
179179
> the first image with the second.
180180
> Images may appear the same size in jupyter,
181-
> but you can see the size difference by comparing the x and y scales for each.
181+
> but you can see the size difference by comparing the scales for each.
182182
> You can also see the differnce in file storage size on disk by
183183
> hovering your mouse cursor over the original
184184
> and the new file in the jupyter file browser, using `ls -l` in your shell,
@@ -407,7 +407,7 @@ so we can use array slicing to select rectangular areas of an image.
407407
Then, we can save the selection as a new image, change the pixels in the image,
408408
and so on.
409409
It is important to
410-
remember that coordinates are specified in *(y, x)* order and that colour values
410+
remember that coordinates are specified in *(ry, cx)* order and that colour values
411411
are specified in *(r, g, b)* order when doing these manipulations.
412412
413413
Consider this image of a whiteboard, and suppose that we want to create a
@@ -426,14 +426,14 @@ as shown in this version of the whiteboard picture:
426426
427427
![Whiteboard coordinates](../fig/board-coordinates.jpg)
428428
429-
Note that the coordinates in the preceding image are specified in *(x, y)* order.
429+
Note that the coordinates in the preceding image are specified in *(cx, ry)* order.
430430
Now if our entire whiteboard image is stored as an skimage image named `image`,
431431
we can create a new image of the selected region with a statement like this:
432432
433433
`clip = image[60:151, 135:481, :]`
434434
435-
Our array slicing specifies the range of y-coordinates first, `60:151`,
436-
and then the range of x-coordinates, `135:481`.
435+
Our array slicing specifies the range of y-coordinates or rows first, `60:151`,
436+
and then the range of x-coordinates or columns, `135:481`.
437437
Note we go one beyond the maximum value in each dimension,
438438
so that the entire desired area is selected.
439439
The third part of the slice, `:`,
@@ -481,7 +481,7 @@ plt.imshow(image)
481481
First, we sample a single pixel's colour at a particular location of the
482482
image, saving it in a variable named `color`,
483483
which creates a 1 × 1 × 3 NumPy array with the blue, green, and red colour values
484-
for the pixel located at *(y = 330, x = 90)*.
484+
for the pixel located at *(ry = 330, cx = 90)*.
485485
Then, with the `img[60:151, 135:481] = color` command,
486486
we modify the image in the specified area.
487487
From a NumPy perspective,

_episodes/04-drawing.md

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ Here is what our constructed mask looks like:
127127

128128
The parameters of the `rectangle()` function `(357, 44)` and `(740, 720)`,
129129
are the coordinates of the upper-left (`start`) and lower-right (`end`) corners
130-
of a rectangle in *(y, x)* order.
130+
of a rectangle in *(ry, cx)* order.
131131
The function returns the rectangle as row (`rr`) and column (`cc`) coordinate arrays.
132132

133133
> ## Check the documentation!
@@ -169,16 +169,16 @@ The function returns the rectangle as row (`rr`) and column (`cc`) coordinate ar
169169
>
170170
> Circles can be drawn with the `skimage.draw.disk()` function,
171171
> which takes two parameters:
172-
> the (y, x) point of the centre of the circle,
172+
> the (ry, cx) point of the centre of the circle,
173173
> and the radius of the circle.
174174
> There is an optional `shape` parameter that can be supplied to this function.
175175
> It will limit the output coordinates for cases where the circle
176176
> dimensions exceed the ones of the image.
177177
>
178178
> Lines can be drawn with the `skimage.draw.line()` function,
179179
> which takes four parameters:
180-
> the (y, x) coordinate of one end of the line,
181-
> and the (y, x) coordinate of the other end of the line.
180+
> the (ry, cx) coordinate of one end of the line,
181+
> and the (ry, cx) coordinate of the other end of the line.
182182
>
183183
> Other drawing functions supported by skimage can be found in
184184
> [the skimage reference pages](https://scikit-image.org/docs/dev/api/skimage.draw.html?highlight=draw#module-skimage.draw).
@@ -200,7 +200,7 @@ The function returns the rectangle as row (`rr`) and column (`cc`) coordinate ar
200200
> > Drawing a circle:
201201
> >
202202
> > ~~~
203-
> > # Draw a blue circle with centre (200, 300) in (y, x) coordinates, and radius 100
203+
> > # Draw a blue circle with centre (200, 300) in (ry, cx) coordinates, and radius 100
204204
> > rr, cc = skimage.draw.disk(center=(200, 300), radius=100, shape=image.shape[0:2])
205205
> > image[rr, cc] = (0, 0, 255)
206206
> > ~~~
@@ -209,7 +209,7 @@ The function returns the rectangle as row (`rr`) and column (`cc`) coordinate ar
209209
> > Drawing a line:
210210
> >
211211
> > ~~~
212-
> > # Draw a green line from (400, 200) to (500, 700) in (y, x) coordinates
212+
> > # Draw a green line from (400, 200) to (500, 700) in (ry, cx) coordinates
213213
> > rr, cc = skimage.draw.line(r0=400, c0=200, r1=500, c1=700)
214214
> > image[rr, cc] = (0, 255, 0)
215215
> > ~~~
@@ -438,7 +438,7 @@ The resulting masked image should look like this:
438438
> Your task is to write some code that will produce a mask that will
439439
> mask out everything except for the wells.
440440
> To help with this, you should use the text file `data/centers.txt` that contains
441-
> the (x, y) coordinates of the centre of each of the 96 wells in this image.
441+
> the (cx, ry) coordinates of the centre of each of the 96 wells in this image.
442442
> You may assume that each of the wells has a radius of 16 pixels.
443443
>
444444
> Your program should produce output that looks like this:
@@ -459,11 +459,11 @@ The resulting masked image should look like this:
459459
> > for line in center_file:
460460
> > # ... getting the coordinates of each well...
461461
> > coordinates = line.split()
462-
> > x = int(coordinates[0])
463-
> > y = int(coordinates[1])
462+
> > cx = int(coordinates[0])
463+
> > ry = int(coordinates[1])
464464
> >
465465
> > # ... and drawing a circle on the mask
466-
> > rr, cc = skimage.draw.disk(center=(y, x), radius=16, shape=image.shape[0:2])
466+
> > rr, cc = skimage.draw.disk(center=(ry, cx), radius=16, shape=image.shape[0:2])
467467
> > mask[rr, cc] = False
468468
> >
469469
> > # apply the mask
@@ -491,9 +491,9 @@ The resulting masked image should look like this:
491491
> we could produce our well plate mask without having to
492492
> read in the coordinates of the centres of each well.
493493
> Assume that the centre of the upper left well in the image is at
494-
> location x = 91 and y = 108, and that there are
495-
> 70 pixels between each centre in the x dimension and
496-
> 72 pixels between each centre in the y dimension.
494+
> location cx = 91 and ry = 108, and that there are
495+
> 70 pixels between each centre in the cx dimension and
496+
> 72 pixels between each centre in the ry dimension.
497497
> Each well still has a radius of 16 pixels.
498498
> Write a Python program that produces the same output image as in the previous challenge,
499499
> but *without* having to read in the `centers.txt` file.
@@ -512,28 +512,28 @@ The resulting masked image should look like this:
512512
> > mask = np.ones(shape=image.shape[0:2], dtype="bool")
513513
> >
514514
> > # upper left well coordinates
515-
> > x0 = 91
516-
> > y0 = 108
515+
> > cx0 = 91
516+
> > ry0 = 108
517517
> >
518518
> > # spaces between wells
519-
> > deltaX = 70
520-
> > deltaY = 72
519+
> > deltaCX = 70
520+
> > deltaRY = 72
521521
> >
522-
> > x = x0
523-
> > y = y0
522+
> > cx = cx0
523+
> > ry = ry0
524524
> >
525525
> > # iterate each row and column
526526
> > for row in range(12):
527-
> > # reset x to leftmost well in the row
528-
> > x = x0
527+
> > # reset cx to leftmost well in the row
528+
> > cx = cx0
529529
> > for col in range(8):
530530
> >
531531
> > # ... and drawing a circle on the mask
532-
> > rr, cc = skimage.draw.disk(center=(y, x), radius=16, shape=image.shape[0:2])
532+
> > rr, cc = skimage.draw.disk(center=(ry, cx), radius=16, shape=image.shape[0:2])
533533
> > mask[rr, cc] = False
534-
> > x += deltaX
534+
> > cx += deltaCX
535535
> > # after one complete row, move to next row
536-
> > y += deltaY
536+
> > ry += deltaRY
537537
> >
538538
> > # apply the mask
539539
> > image[mask] = 0

_episodes/06-blurring.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ blurred = skimage.filters.gaussian(
257257
{: .language-python}
258258
259259
The first two parameters to `skimage.filters.gaussian()` are the image to blur,
260-
`image`, and a tuple defining the sigma to use in y- and x-direction,
260+
`image`, and a tuple defining the sigma to use in ry- and cx-direction,
261261
`(sigma, sigma)`.
262262
The third parameter `truncate` gives the radius of the kernel in terms of sigmas.
263263
A Gaussian function is defined from -infinity to +infinity, but our kernel
@@ -311,13 +311,13 @@ plt.show()
311311
> ## Experimenting with kernel shape (10 min - optional, not included in timing)
312312
>
313313
> Now, what is the effect of applying an asymmetric kernel to blurring an image?
314-
> Try running the code above with different sigmas in the y and x direction.
315-
> For example, a sigma of 1.0 in the y direction, and 6.0 in the x direction.
314+
> Try running the code above with different sigmas in the ry and cx direction.
315+
> For example, a sigma of 1.0 in the ry direction, and 6.0 in the cx direction.
316316
>
317317
> > ## Solution
318318
> >
319319
> > ~~~
320-
> > # apply Gaussian blur, with a sigma of 1.0 in the y direction, and 6.0 in the x direction
320+
> > # apply Gaussian blur, with a sigma of 1.0 in the ry direction, and 6.0 in the cx direction
321321
> > blurred = skimage.filters.gaussian(
322322
> > image, sigma=(1.0, 6.0), truncate=3.5, multichannel=True
323323
> > )

_extras/edge-detection.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ The skimage `skimage.feature.canny()` function performs the following steps:
8787
is applied to remove noise from the image.
8888
(So if we are doing edge detection via this function,
8989
we should not perform our own blurring step.)
90-
2. Sobel edge detection is performed on both the x and y dimensions,
90+
2. Sobel edge detection is performed on both the cx and ry dimensions,
9191
to find the intensity gradients of the edges in the image.
9292
Sobel edge detection computes
9393
the derivative of a curve fitting the gradient between light and dark areas

0 commit comments

Comments
 (0)