Advent of Code is back! Unwrap daily challenges to sharpen your Alteryx skills and earn badges along the way! Learn more now.
Free Trial

Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
SOLVED

Error with "Extracting Colors from an Image"

bnjmnsmith
8 - Asteroid

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))

Alteryx Error.JPG

 

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)

 

7 REPLIES 7
BenMoss
ACE Emeritus
ACE Emeritus

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

bnjmnsmith
8 - Asteroid

Here's what I'm looking at:

 

Alteryx Error2.JPG

BenMoss
ACE Emeritus
ACE Emeritus

Sorry @bnjmnsmith I meant specifically the .png file that you are trying to load.

 

Ben

BenMoss
ACE Emeritus
ACE Emeritus

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)
)
bnjmnsmith
8 - Asteroid

Test.pngHah! Oh, this thing. It's a simple picture I created to practice on.

bnjmnsmith
8 - Asteroid

Alteryx Error2.JPG

 

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!!!

bnjmnsmith
8 - Asteroid

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!

 

Solution.JPG

Labels
Top Solution Authors