🌈 ESP32-S3 Rainbow: ZX Spectrum Emulator Board! Get it on Crowd Supply →
View All Posts
read
Want to keep up to date with the latest posts and videos? Subscribe to the newsletter
HELP SUPPORT MY WORK: If you're feeling flush then please stop by Patreon Or you can make a one off donation via ko-fi

I’ve been making some improvements to the blog. In the previous post, I talked about how I was using ChatGPT to generate tags, summaries and lists of related articles. If that’s working correctly then the previous post should appear in the list of related articles below. If it’s not then - here’s a direct link: Improving My Blog Using AI.

We finished the post with my complaint that I was missing a lot of header images on some of the older posts, making the front page look a bit boring:

Missing Images

I’ve always struggled with getting ChatGPT to generate good image prompts. It always seems to stray into a very instructional-type reply as if it’s briefing a designer which doesn’t seem to produce the best results. However things seemed to have improved a lot recently, so I thought I’d give it another go.

Here’s a list of suggestsion from ChatGPT4 for the Home Automation with ChatGPT post:

Give me an image prompt for DALL-E 2 that would be a faithful representation of the article below.

---
CONTENTS
---

Produces this:

An animated Raspberry Pi is controlling a variety of household lights, including in the kitchen, bedroom, dining table, bathroom, and lounge. Each light is symbolized by a unique icon reflecting its location. Chat bubbles emerge from the Raspberry Pi, containing phrases like 'Let there be light,' and 'Time for breakfast.' As the phrases are spoken, the respective lights glow brighter. On a screen behind the scene, snippets of Python code and an OpenAPI yaml file are visible, symbolizing the ChatGPT-generated code that's controlling this smart home automation.

It’s a bit long and a bit too detailed, but we can give it ago. This is what DALL-E 2 produced:

DALL-E 2 Image

It’s not too bad, we have some things that look vaguely Raspberry Pi-like - there’s even a raspberry in one of the images. But when we compare it with what Midjourney can produce it looks a bit rubbish:

Midjourney Image

Midjourney has produced a much more aesthetically pleasing image (at least to my eye). We’re not really trying for a perfect representation of the article, we’re just trying to make the front page look a bit more interesting. The other nice thing with Midjourney is that we can specify the aspect ratio of the image we want. With DALL-E 2 we’re stuck with a square image. There are various ways of getting around this limitation with shrinking the image, followed by inpainting and then cropping but it’s a pain.

So, I’d quite like to use Midjourney. As always though, there is a catch.

There’s no API for Midjourney, access is only available via Discord. And the terms of service are pretty strict around automation and scripting:

You may not reverse engineer the Services or the Assets. You may not use automated tools to access, interact with, or generate Assets through the Services.

So, we’re definitely not allowed to automate anything!

But, it’s fun to think about how you would automate it - not that I would ever contemplate doing this, nor would I encourage or suggest anyone else to do so either!

There are a couple of options that spring immediately to mind:

  • Using GUI automation tools to drive the discord desktop client
  • Using Webdriver to drive the discord web client

There’s a popular library called PyAutoGUI that looks like it would work for driving the desktop client.

However, looking at the docs it feels like it would be very fragile, you are moving the mouse to specific X and Y coordinates, then clicking on things. You’d have to be very careful to arrange the windows in exactly the right place and then not touch the computer. So it’s not ideal.

Webdriver feels like the easiest approach and if you do a bit of googling, you’ll find some suitable code that can be hacked together - not that I’d ever do anything like that of course!

Assuming you’ve managed to get Midjourney to generate all the images you need (either by copying and pasting or by more nefarious means), you now have another problem. How do you download all your images?

The easiest way to do this is just to go to the Midjourney website and you can see all your images.

Midjourney Images

Whenever I’m faced with a web scraping challenge, my first stop is to open up the dev tools and see if there are any ā€œFetch/XHRā€ requests going on.

Network Requests

Amongst all the tracking and analytics requests that are being blocked by the browser we can see a pretty interesting one:

https://www.midjourney.com/api/app/recent-jobs/?amount=35&dedupe=true&jobStatus=completed&jobType=grid&orderBy=new&prompt=undefined&refreshApi=0&searchType=advanced&service=null&type=all&userId=80585519-76f3-4e8b-b2ab-3eedda0c9d61&user_id_ranked_score=null&_ql=todo&_qurl=https%3A%2F%2Fwww.midjourney.com%2Fapp%2F

And if we scroll down the images to the load more button and click on it. Then we see another request, but this time we’ve got an extra parameter - page=2:

https://www.midjourney.com/api/app/recent-jobs/?amount=35&dedupe=true&jobStatus=completed&jobType=grid&orderBy=new&page=3&prompt=undefined&refreshApi=0&searchType=advanced&service=null&toDate=2023-05-27+13%3A01%3A44.226263&type=all&userId=80585519-76f3-4e8b-b2ab-3eedda0c9d61&user_id_ranked_score=null&_ql=todo&_qurl=https%3A%2F%2Fwww.midjourney.com%2Fapp%2F

The response to both these requests looks very useful. We get a list of results along with links to each of the 4 images that make up the grid - perfect!

Response

At this point, we could try and get clever and write a script to drive the API and go through each page. But really we don’t need to bother, we’re only interested in the latest couple of pages, so we can just copy and paste the response into a file. Sometimes it really is just quicker not to write a script!

With the JSON response in a file, we can run through each result, match up the original caption with the generated image and download the four images.

Our next challenge is: Which of the four images do we want to actually use?

I was thinking about getting a description for each image and then going back to ChatGPT to ask which image most closely matched the article, but it was quite hard to find something I could use for this.

So I asked ChatGPT for some suggestions:

What are some simple statistics that can be extracted from an image to determine how "interesting" it is?

And it came back with some interesting suggestions ranging from fairly simple to quite complex:

Determining what makes an image "interesting" can be quite subjective and often depends on the context and viewer. However, there are indeed some quantifiable characteristics that researchers have associated with the perceived interest or attractiveness of an image:

1. **Color diversity**: Images with a greater variety of colours can be more visually interesting. This can be measured as the number of unique colours or by using entropy in the colour space.

2. **Texture complexity**: Similarly, an image with more complex texture patterns could be more interesting. Texture can be measured by analyzing the spatial distribution of colours or brightness in an image.

3. **Contrast**: High-contrast images can be more visually striking. Contrast can be measured statistically as the standard deviation of the brightness (i.e., grayscale intensity) of the pixels.

4. **Spatial Frequency**: Studies have shown that people tend to find images with more medium-frequency content to be more pleasing. You can extract this via a Fourier transform.

5. **Symmetry**: Images with some degree of symmetry can be appealing, especially bilateral symmetry. Various measures of symmetry can be derived depending on the exact definition used.

6. **Presence of Faces**: Humans are naturally attracted to faces. The number and size of faces detected can be an interesting measure. This requires a face detection algorithm.

7. **Object Recognition**: Recognizable objects or features could make an image more interesting. This requires more sophisticated techniques like object detection or semantic segmentation.

8. **Depth of Field**: Images with a shallow depth of field (where the subject is in focus and the background is blurred) are often seen as more aesthetically pleasing. This requires techniques like edge detection and depth estimation.

9. **Rule of Thirds**: This is a guideline which proposes that an image should be imagined as divided into nine equal parts by two equally spaced horizontal lines and two equally spaced vertical lines, and that important compositional elements should be placed along these lines or their intersections. There are ways to determine how well an image follows this rule.

10. **Saliency**: Saliency models predict which areas of an image are likely to attract attention. These models are often based on the idea that humans are more likely to focus on areas of high contrast or unique features.

Remember, these are just guidelines and not hard-and-fast rules. They might be a starting point to build an algorithm to evaluate the "interestingness" of an image, but personal and cultural differences, as well as the context in which the image is viewed, will also greatly influence this judgement.

I tried out the first few of these as they were pretty easy to implement. In the end, I just plumped for contrast as it seemed to work ok. The problem with Midjourney is that generally, all the images look really nice, so it is kind of arbitrary which one you pick.

Here are a couple of examples with the best image highlighted:

Raspberry Pi Temperature Sensor

Heart Rate Free - How it works.webp

I would definitely like to revisit this at some point though as it’s pretty interesting.

All the articles have been updated to their new images. Here’s what the old pages used to look like:

Before

And here’s what it looks like now!

After

I think it’s pretty nice! You could argue that most of these old posts are kind of irrelevant now and I could have just left them. But I’ve learned a lot from this fun bit of scripting and the blog looks much nicer. So I’m happy!

Related Posts

Improving My Blog Using AI - In this blog post, I detail how I've made significant improvements to my long-time blog by integrating advanced AI tools. Using OpenAI's ChatGPT, I've successfully automated the tagging of my articles and generating precise summaries for each, enhancing my blog's navigability and readability. I also discuss how I used AI to generate related content, making my blog more engaging and interconnected. To top it off, I hint at an upcoming feature: AI-created images to beautify my blog posts!
Augmented Reality In The Browser - This blog showcases the progress of my idea to create an augmented reality Sudoku solver using technology that enables us to solve puzzles in our browser rather than with dedicated apps. I have developed an AR Sudoku solver with a simple image processing pipeline. It identifies and extracts Sudoku puzzles from pictures, recognizes each cell's numbers, solves the puzzle, and renders the solution on top of the original image. This process is accomplished by converting the image to greyscale, conducting thresholding, OCR-processing, and puzzle-solving. I've also done parallel image location and extraction. It's a technical journey that's achieved some high-quality, low-drift results, visible in the video included. The full codebase is accessible on Github. Enjoy the joy of leveraging technology to efficiently solve Sudoku puzzles!
Vibing a PCB - surprisingly good - In my latest adventure, I challenged AI to design a working ESP32-S3 development board from scratch using Atopile and Claude. The idea was as simple as vibe-coding actual hardware without diving into the code. It was a chaotic yet fascinating journey, with some misses like unwired components and a forgotten capacitor. After a few prompts, the AI delivered a surprisingly functional board featuring USB-C, an AMS1117 regulator, and status LEDs. While not yet perfect, vibe-coding feels like a glimpse into the future of hardware design.
Vision Kit and CoreML - In this technical tutorial, we walk through the process of wiring up the iPhone's camera to CoreML using Vision Kit, allowing us to run machine learning models against the camera input. We outline the necessary steps in creating a new Xcode project; capturing video frames; using AVFoundation, Vision, and CoreML; and dissecting the video frames using Vision magic. We also illustrate the process of running our Vision requests and displaying the expected outputs.
Cropping the results from UIImagePickerController - Wrestled with UIImagePickerControllerCropRect today for cropping images. Some of the codes out there were ridiculously long winded, so I took a stab at whittling it down myself. Safely arrived at a streamlined solution that dealt with the size of image, the crop rect and graphics context. Also worked in a neat bit on image orientation. Law of parsimony victorious!

Related Videos

Printing PCBs At Home! - In today's captivating episode, I take a shot at home printed PCBs rather than buying from our faithful PCBWay, leading to some riveting discoveries. Using a stunning Voltera machine, my single-sided print echoed a glistening marshmallow-like texture that was cured just lovely in the oven. Encountering limitations, such as weak conductive ink bonds and layout tricks, brought on new challenges but also widened my horizon for potential improvements, such as considering a direct USB connection experiment. Despite issues, our creation came to life through intriguing stages of soldering, placement, and reflow, resulting in a successful quick prototype with operational LEDs and programmable features! Our exploration does remind me of the value of PCBWay though so have no fear, our Atomic 14-PCBWay partnership continues on. Keep watching for more such adventures!
Surprisingly not CR*P - Vibing hardware - Well folks, what an adventure! After vibe coding our vibing button, I took up the challenge to vibe code the actual hardware for an ESP32 S3 dev board. Used a tool called at pile and gave it a whirl with some AI help from Claude. Interestingly, it handled everything from sourcing components with LCSC part numbers to wiring them up. Had a wee hiccup with missing capacitor in the RC circuit, but overall it was a thrilling ride watching the AI process! A bit of tweaking here and there, and we're good to go! Can't wait to see it in action.
256 Shades of Grey – Adventures in Image Processing - In this enlightening video, I delve into the deep and fascinating world of image processing. Forget everything you thought you knew about pixels – they’re not squares or rectangles and they definitely aren’t discs. All pixels are, my friends, are point samples, each capturing brightness or color at a particular position. Curious to know how to manipulate them? I also unravel this mysterious tapestry, familiarizing you with the technicalities of grayscale, RGB, HSB, YUV, and a fleeting mention of CMYK. And if you think that's all, hold tight! Did you know we could apply Fourier transforms, akin to graphic equalisers used in audio, to our good old two-dimensional images? Strap in as I guide you through this potentially overwhelming realm with a pinch of humor, lots of simplicity, and oodles of practical examples.
ESP32-TV Version 3 - Is it done? - In today's project update, I'm excited to share that my ESP32-TV boards, fresh from PCBWay, are operating flawlessly! We've successfully dealt with the USB2244 conflict with the ESP32, and the battery charging issue is now a thing of the past. We've also made some awesome additions like a microphone to our board. The real MVP though, is the USB2244 chip that’s given us significantly improved read/write speeds - making it perfect for handling video files. Next on the agenda, figuring out a solution for the non-standard display connector. As ever, there’s progress, there’s problems, and there's David Bowie animated gifs!
Arduino Nano ESP32 - It's nice - But probably not for me. - In this video, I took a deep dive into the Arduino Nano ESP32 and compared it with other available boards in the market. Despite its seemingly high cost as compared to the options on AliExpress, its overall quality, fantastic documentation, and the fact that it fits neatly into the Arduino ecosystem makes it a good buy, especially if you've already invested in the Arduino Nano and its shields. The board has a few interesting peculiarity, including the use of a NORA-W106 module, a switch mode step-down converter for power, and an RGB LED. However, I was disappointed to find out it doesn't come with built-in battery charging. The pin labelling and remapping could definitely cause some confusion, especially if you're transitioning from other ESP32 boards. It's a fairly decent ESP32-S3 board if that's what you're after. But given a choice, I'm keener on the Unexpected Maker boards or the cheap boards on AliExpress.
HELP SUPPORT MY WORK: If you're feeling flush then please stop by Patreon Or you can make a one off donation via ko-fi
Want to keep up to date with the latest posts and videos? Subscribe to the newsletter
Blog Logo

Chris Greening


Published

> Image

atomic14

A collection of slightly mad projects, instructive/educational videos, and generally interesting stuff. Building projects around the Arduino and ESP32 platforms - we'll be exploring AI, Computer Vision, Audio, 3D Printing - it may get a bit eclectic...

View All Posts