Monday, February 27, 2023

AI - Why Humans will Need a Label

In This Edition:

  • Can ChatGPT write code?
  • Humans need a Label

Can ChatGPT write code?

Continuing on last month's sermon about these new "AI" machine learning tools used to generate images, I also thought I'd give ChatGPT a chance to help me with a programming need.  I had a folder with 500 images in it of various sizes and formats, and wanted to shrink just some of them and save them to a different directory using the original file type.  You can't use Photoshop actions for this because it lacks the ability to do an "IF - THEN".

So I asked this question of ChatGPT and my jaw dropped when I saw its response: 

===

Me: Can you write a Photoshop script that goes through every image in a folder, shrinks an image to 6" wide at 72 dpi only if the original image is larger than that, then save it in a different directory as either a .jpg of quality 4 or a .png file of smallest size depending on what kind of file the original image was?

ChatGPT: Here is a sample script in Adobe Photoshop's scripting language, JavaScript, that accomplishes the task you described.  The script can be run using Adobe Photoshop's scripting functionality, which can be accessed through the "File" menu.  The code it gave me appears in the scrollbox below:

// Specify the source folder

var srcFolder = Folder.selectDialog("Select the source folder");

// Specify the destination folder

var dstFolder = Folder.selectDialog("Select the destination folder");

// Get a list of all files in the source folder

var fileList = srcFolder.getFiles();

// Loop through each file in the source folder

for (var i = 0; i < fileList.length; i++) {

  // Open the current file

  var file = fileList[i];

  if (file instanceof File && file.hidden == false) {

    app.open(file);

    // Check if the image is wider than 6 inches at 72 DPI

    if (app.activeDocument.width > (6 * 72)) {

      // Calculate the new width in pixels

      var newWidth = 6 * 72;

      // Resize the image

      app.activeDocument.resizeImage(UnitValue(newWidth, "px"), null, 72, ResampleMethod.BICUBIC);

      // Get the file extension of the original image

      var fileExtension = app.activeDocument.name.split(".").pop().toLowerCase();

      // Compose the new file name

      var newName = dstFolder.fsName + "/" + app.activeDocument.name.split(".")[0] + "_resized." + fileExtension;

      // Save the resized image

      if (fileExtension == "jpg") {

        var jpgSaveOptions = new JPEGSaveOptions();

        jpgSaveOptions.quality = 4;

        app.activeDocument.saveAs(new File(newName), jpgSaveOptions, true, Extension.LOWERCASE);

      } else if (fileExtension == "png") {

        var pngSaveOptions = new PNGSaveOptions();

        pngSaveOptions.compression = 0;

        pngSaveOptions.interlaced = false;

        app.activeDocument.saveAs(new File(newName), pngSaveOptions, true, Extension.LOWERCASE);

      }

    }

    // Close the current document

    app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);

  }

}


I was gobsmacked when I saw it spit out perfect-looking code - complete with comments!!  But my enthusiasm waned when I ran the program.  

"This code doesn't work" I protested to the chatbot.  "The destination directory is empty, even though it looked like everything ran properly."  ChatGPT went into "blame the victim" mode, suggesting that perhaps I didn't have permission to write files there.  (I did.)

So I spent the better part of the day debugging the program.  And I found that ChatGPT had made a common beginner's mistake: the default units of measurement for some functions were sometimes in inches and sometimes in pixels.  So all of the images tested were thought to be the wrong size and so the conditional commands were never executed.

I went back to ChatGPT and we had this conversation:

Me: The units were wrong. Sometimes the image width was measured in inches; sometimes it was measured in pixels.

ChatGPT: You can modify the script to handle both cases. Here's a modified version of the script that takes into account the units of the original image width:

// Specify the source folder

var srcFolder = Folder.selectDialog("Select the source folder");

// Specify the destination folder

var dstFolder = Folder.selectDialog("Select the destination folder");

// Get a list of all files in the source folder

var fileList = srcFolder.getFiles();

// Loop through each file in the source folder

for (var i = 0; i < fileList.length; i++) {

// Open the current file

var file = fileList[i];

if (file instanceof File && file.hidden == false) {

app.open(file);

// Get the width of the image in pixels

var originalWidth = app.activeDocument.width.as("px");

// Check if the image is wider than 6 inches at 72 DPI

if (originalWidth > (6 * 72)) {

// Calculate the new width in pixels

var newWidth = 6 * 72;

// Resize the image

app.activeDocument.resizeImage(UnitValue(newWidth, "px"), null, 72, ResampleMethod.BICUBIC);

// Get the file extension of the original image

var fileExtension = app.activeDocument.name.split(".").pop().toLowerCase();

// Compose the new file name

var newName = dstFolder.fsName + "/" + app.activeDocument.name.split(".")[0] + "_resized." + fileExtension;

// Save the resized image

if (fileExtension == "jpg") {

var jpgSaveOptions = new JPEGSaveOptions();

jpgSaveOptions.quality = 4;

app.activeDocument.saveAs(new File(newName), jpgSaveOptions, true, Extension.LOWERCASE);

} else if (fileExtension == "png") {

var pngSaveOptions = new PNGSaveOptions();

pngSaveOptions.compression = 0;

pngSaveOptions.interlaced = false;

app.activeDocument.saveAs(new File(newName), pngSaveOptions, true, Extension.LOWERCASE);

}

}

// Close the current document

app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);

}

}

THAT worked!

Moral to the story #1: This stuff won't put programmers out of work, but it will save them a considerable amount of time by quickly producing code they can tweak. (That's no different from how programmers do their job now: Search Google for a code fragment (usually from from StackOverflow.com) and tweak from there.)

Moral to the story #2: Garbage in, garbage out.  Chatbots only mirror what's on the internet, which has grown to become a cesspool of ignorance with some chemtrails thrown in.  And it's about to get worse... read on.

Humans Need a Label

As a self-referential joke, I asked MidJourney to design a logo certifying that something was "A.I.-free".  Of course it couldn't do the lettering right.  I wanted it to say, "The Order of Flesh and Blood", a title taken from the 1950's science fiction movie The Creation of the Humanoids.  Anyway, this will now be the basis of my standard disclaimer, whose final version appears at the top of this post, letting people know that my creations were generated by a human and not via generative AI or machine learning.







Since last month's diatribe it seems that AI has exploded onto the scene (at least all the tech news outlets), some of them positive ("ChatGPT can find case law faster and easier than using conventional keyword searches") (oh wait, that's a lie!), but most of them negative ("Look at all of these factual errors it's confidently spitting out!!", or "This can be used to easily create malware!").  Then I read that some people have empathy for these things, and some have been using chatbots to write books with little to no effort and self-publish them on Amazon, with the promise of exponentially amplifying the amount of crap out there.  As they proliferate, we'll need some humans to sort through what's factually correct to increase the value of its output.  Back in my day, those people were called "editors".  

It then occurred to me that there will soon be a need for certification - similar to what the farmers' associations came up with to let consumers know whether their crops were organic, or whether a food product contained preservatives.  There will be a need for people who don't want to double-check every fact spit out by a chatbot, to know that what they're consuming has had some human quality control on it to weed out demonstrable falsehoods (Flat Earth?  5G towers cause COVID?), label rumors appropriately ("Climate Change is a hoax from China"), and to give proper historical context.  Plus, it's been demonstrated that those tools that can allegedly detect if ChatGPT had been used to create something are about as reliable as the chatbot output they're trying to authenticate.

So while last month I proposed a law firm that would sue the misbehaving AI models and whip them into shape,  this month I propose that all content created without the use of AI be voluntarily labeled as such.  Of course definitions would have to be worked out, just as it had with farming (there were many definitions of "organic" in the beginning, for example).  And there will be shades of grey even for photographers - for example, should Photoshop (which has some AI tools built-in) count?

Taking this idea a step further, I recall how typewritten letters were once highly regarded when they first appeared, conveying an aura of importance and stature and those were the letters people opened first.  Then when printed letters became the norm, handwritten letters suddenly stuck out as being novel and attention-worthy.  And I think the same thing might happen in photography.  Currently there's no image on the internet that hasn't been post-processed in some way.  I wonder if in the near future scanned transparencies with no post-processing will somehow become more valued because they tell the "truth" more than images that have been manipulated to look more pleasing (which is usually synonymous with lying).  Traditionalists can make their mark by being different - only producing SOOC images!!!  Getting it right in the camera like we used to back in the day!!!  Hey, Peter Lik is a millionaire who people perceive as being a photographic god because he shoots with film.  Or you could employ the Trustworthy Digital Camera I invented to verify that the image you took hadn't been manipulated at all.  Same idea - you're certifying that the content was created by a human and not by a machine learning algorithm.

(Just some 3:00 AM thoughts.  I can easily see heated debates going on about this, especially since the internet, whose content was curated by humans, wasn't all that great before the latest AI tools appeared in full force.  But at least it's something.)

Yours Truly, 
Gary Friedman

Disclaimer: No AI tools were used in the creation of this blog post.  (Except for that logo I called out.)


11 comments:

  1. For photographers chatgpt isn't a problem, but text-to-image AI such as Midjourney. You can create e.g. perfect portraits in just seconds from scratch. No difference to studio. Just try it out. Both, AI and "real photos" are some kind of art - but needs to be identified in future.

    ReplyDelete
    Replies
    1. Did you read last month's blog post, by chance? https://friedmanarchives.blogspot.com/2023/01/ai-alarmists-are-worried-about-wrong.html

      Delete
  2. Great article. I have had similar thoughts. Photography is a lost cause I think. The manipulation if pixels will get more and more subtle where it becomes next to impossible to tell how much manipulation has occurred.

    ReplyDelete
    Replies
    1. It's a good thing I invented that digital camera whose output could be authenticated that nobody wanted. https://friedmanarchives.blogspot.com/2020/03/i-invented-camera-whose-output-could-be.html

      Delete
  3. Remember where photography began. It was a progression from pinhole projections on canvas for painters, upside down images that artists did not realize contributed to their right brain technique. Then the first cameras were the evolution of projections on canvas to ultimately being projections on paper.

    Then the first photographers mimicked painting and were called pictorialists. It wasn’t til the f64 movement that the camera pushed the envelope on fulfilling the machine’s potential.

    Today we are fulfilling the digital machine’s potential both in camera and in post. Human need for instant gratification aside, we are the artists in all of the above history. And we still are!

    ReplyDelete
    Replies
    1. I love a good 30,000-foot view! Thanks for this perspective.

      Delete
  4. Oof, Peter Lik might not be the best name to invoke for photographic purity. The guy clearly photoshops the hell out of his images and often claims they were done in a single shot on film, with no retouching. I remember when his "Bella Luna" shot was on display in his gallery in Vegas. The caption at the time read that he peeked out of his tent in the cold night and was astonished by the moon rising over the mountains. He raised his camera to his eye and took a single shot to immortalize the moment forever. This is the "single photo" he took: https://lik.com/products/bella-luna

    Uhh, gee, that's a very clear moon for being a handheld shot at that zoom level. Also... why is the purple atmospheric haze BEHIND the moon?

    Anyway, you might have meant it as a tongue-in-cheek or sarcastic reference, in which case I apologize for reading it wrong.

    ReplyDelete
  5. I agree with you, which is why I used the phrase "perceived as being a photographic god". I hadn't seen that moon shot before but I doubt his mythological explanation of the shot is true; the actual moon is about a zillion times brighter than a star-lit sky at dawn and it surely exceeds the dynamic range of even a specialty film; plus it's hard to believe that a telephoto lens of that strength (I'm guessing 1000mm) has enough depth-of-field to get both the moon and the tree in focus. It's a beautiful image, though, and I have to hand it to Peter for marketing his work so effectively.

    ReplyDelete
  6. That's actually a really sharp logo. Pity the text isn't on a separate layer of the image, so it could be replaced (by a human) with what you originally wanted.

    ReplyDelete
  7. I really like that circular design. I'd like to use it as a basis for a logo. Can you give me the contact info of the designer?

    ReplyDelete
    Replies
    1. Not sure if you're kidding or not... Check the caption under the logo.

      Delete

Thank you for your comment! All comments must be approved by a moderator before they will appear.