My first foray into colour-work knitting was through Shetland Wool Week. Shetland Wool Week is a week long event celebrating Britain’s most northerly native sheep, the Shetland textile industry and the rural farming community.
Each year a designer creates a knitting pattern for a hat for the week. They are wonderful designs and a great way of connecting knitters around the world. You never know where you’ll meet a Shetland Wool Weeker!
My first ever colour-work project was knitting Gudrun Johnston’s Bousta Beanie hat. It’s been a real delight this year to revisit the pattern as my wedding present to two friends, Julianna and Tom, who were married this Spring.
I knit the pattern using Jamieson’s of Shetland 2-ply yarn. My friends were excited and a little overwhelmend by all the possible color combinations they could choose!
As a Professor of Computer Science at College of the Atlantic in Bar Harbor, Maine. I knew there was a way that I could help them choose the colours for their hat using coding and a bit of webscraping! And thus, swatch-creator was born as a way to choose and try out different colors for patterns.
To do this I scraped the photos of the yarns from the Jamieson’s website. I then set about extracting the colors.
# Function to count the colours (adapted from Jeroen Ooms and Matt Dray: https://www.rostrum.blog/2018/11/25/art-of-the-possible/)
<- function(image_path) {
get_top_color_blend <- image_read(image_path)
image_i <- image_convolve(image_i, 'Gaussian:0x5', scaling = '60,20%')
img <- image_data(img) %>%
top_hex apply(2:3, paste, collapse = "") %>%
%>% table() %>% as.data.frame() %>%
as.vector setNames(c("hex", "freq")) %>%
mutate(hex = paste("#", hex, sep="")) %>%
slice_max(order_by = freq, n = 1) %>%
pull(hex)
return(top_hex) # Keep researching to eplace with average
}
<- function(image_path) {
get_top_color <- image_read(image_path)
img <- image_data(img) %>%
top_hex apply(2:3, paste, collapse = "") %>%
%>% table() %>% as.data.frame() %>%
as.vector setNames(c("hex", "freq")) %>%
mutate(hex = paste("#", hex, sep="")) %>%
slice_max(order_by = freq, n = 3) %>%
pull(hex)
return(top_hex[3]) #
}
<- function(image_path) {
get_top3_color <- image_read(image_path)
img <- image_data(img) %>%
top_hex apply(2:3, paste, collapse = "") %>%
%>% table() %>% as.data.frame() %>%
as.vector setNames(c("hex", "freq")) %>%
mutate(hex = paste("#", hex, sep="")) %>%
slice_max(order_by = freq, n = 3) %>%
pull(hex)
return(top_hex[3]) #
}
I tried a few different methods, either averaging the colours in the image, or picking out the most dominant or second-most dominant colors. I was able to do a good job matching some of the colors, but struggled with the yarns which have lots of beautiful specks in the yarn. Another challenge was the shadowing in some of the pictures, in which case the second-most dominant color was a better match. I’ll continue tinkering with this part of the code to match the colors better.
For their hats my friends chose the following colours: