Hello Genius's!
I read some blog posts by various Alteryx and R artists on how to extract colors from an image. @BenMoss has an awesome one here that was extremely helpful, in fact I used his example more so than other ones.
I'm having trouble with an error in the example Ben has on his blog. I've installed the png R package correctly (I believe), but I keep getting the error below. I've also attached the workbook I'm working in as well as the picture I wanted to use as an example (hidden in the .yxzp file). You'll need to change the filepath to make it work.
THANK YOU!!!
Error in seq.default(0,1, length.out = nrow(z))
This is the code I'm using:
## Open libraries required to complete analysis library("png") library("grid") library("gridExtra") ## Read image into R. This will return a large array of elements ## which contains the RGB values (seperately) for each individual ## pixal within the image image = readPNG("FILE PATH PLACEHOLDER") ## Convert the large array into a data frame containing 3 columns ## one for each of the three RGB values df = data.frame( red = matrix(image(,,1), ncol=1), green = matrix(image(,,1), ncol=1), blue = matrix(image(,,1), ncol=1) ) ## Write our data frame for output write.Alteryx(df, 1)
Solved! Go to Solution.
Hi @bnjmnsmith great to hear you are using the app.
Unfortunately i've not bumped into this error before; I can take a look at this potentially on Friday, but would you be able to share a sample image which is triggering this error.
Ben
Here's what I'm looking at:
I think you need to look at this part...
df = data.frame( red = matrix(image[,,1], ncol=1), green = matrix(image[,,1], ncol=1), blue = matrix(image[,,1], ncol=1) )
It should look like this...
df = data.frame( red = matrix(image[,,1], ncol=1), green = matrix(image[,,2], ncol=1), blue = matrix(image[,,3], ncol=1) )
Hah! Oh, this thing. It's a simple picture I created to practice on.
You are absolutely right about the code. I corrected it as you said. Unfortunately the error is still popping up.
Thank you for your help!!!
Wait!!! I should have looked at this better...I was using parenthesis ( ) instead of brackets [ ]. It works like a charm now!
Thank you for helping me @BenMoss!
User | Count |
---|---|
18 | |
15 | |
13 | |
9 | |
8 |