How to get polar coordinates of pixels in an image?

Update: I have the script generating a seemingly correct text data file with the positions of black pixels, but the second sketch to be used to recreate the image based on the text file data is not doing anything. Also, it runs extremely slow (1-5 minutes) which isn’t an issue but is annoying. Take a look please.

//float r = 0;
int z = 0;
float r = 0;
float theta = 0;
//float theta = 0;
PImage input;
String[] output;

void setup() {
  size(300, 300);
  background(255);
  output = new String[1];
  output[0] = "";
  selectInput("select an image to process", "select");
}
void select(File selection){
  if (selection == null){
    exit();
  }
  else {
    input = loadImage(selection.getAbsolutePath());
    input.resize(width, height);
    input.filter(THRESHOLD, 0.5);
    input.loadPixels();

//void draw() {
  while (z < 49950) {
  // Polar to Cartesian conversion
  float x = r * cos(theta);
  float y = r * sin(theta);

  
  int xx = int((x+width/2));
  int yy = int((y+height/2));
  if (z > 2000) {
  if(input.pixels[yy * width + xx] == color(0)) {
  //int pixelz = get(xx,yy);
  //if (pixelz == color(0)) {
    output[0] += z + "\n";
    println(z);
  //point(xx, yy);
  }
  }
  // Increment the angle
  theta += 0.01;
  // Increment the radius
  r += 0.003; //0.001 covers all pixels
  z = z + 1;
}
saveStrings("cmds.txt", output);
println("done!");
}
  }

Verifier / recreator:

String[] input;
float r = 0;
int z = 0;
float theta = 0;
int count = 0;
int pix;
void setup() {
  size(300,300);
  background(255);
  input = loadStrings("cmds.txt");
  loadPixels();
  while (z < 49950) {
    println(z);
    float x = r * cos(theta);
    float y = r * sin(theta);
    int xx = int((x+width/2));
    int yy = int((y+height/2));
    if (z > 2000) {
    for(int i = 0; i < input.length; i ++) {
     int pix = int(input[i]);
     if (z == pix) {
     point(xx,yy);
     }
     //theta += 0.01;
     //r += 0.003;
     //z = z +1;
    
    }
    }
    theta += 0.01;
     r += 0.003;
     z = z +1;
  }
  
  println("done");
}