Showing posts with label instruction. Show all posts
Showing posts with label instruction. Show all posts

Saturday, February 08, 2025

Techniques of wallpaper generation

 kw: instruction, ai art, upscaling, wallpaper, screen shows

Introduction

I am a collector. One type of collection is sets of images that make good screen wallpaper. My folders of screen wallpaper images includes masses of flowers, mineral crystals (particularly in masses), selections from Hubble and JWST astrophotographs, waterfall photos, and landscape paintings. Now that I've been experimenting with art generation using various SI (Simulated Intelligence) programs, I have a growing body of work in several genres.

My computer setup has two screens with resolutions of 1920x1080, or standard HD. Anticipating that sometime in the future I may transition to one or two 4K screens (3840x2160 or UHD), when I encounter an image that size or larger I don't reduce its size, but keep it for the future. However, I usually reshape an image by cropping it to a 16:9 aspect ratio. I use the "screen saver" program gPhotoshow to cycle through one or more folders of images I want to display during idle time.

This post is in two parts. Firstly I discuss the production of an image of appropriate size and aspect ratio, beginning with the seven image sizes produced by the five programs I have been using. Secondly I explain how I sign an image to give credit to myself and the program that I used, especially matching the signature size with the image size.

Image Sizes and How to Treat Them

This is a reduced version of an image I produced in my "Troglodyte" series. A troglodyte is a cave dweller. I call my basement library-and-computer-room my Man Cave, though most men who have such a space use it for watching sports. I decided to play with the idea of having an office in a real cave. Eventually I produced more than ten rooms, as though I owned a cave large enough to convert into a sort of mansion, which was dry enough that my furnishings would not mildew.

I was also experimenting with lengthy prompts for this project, but that is less critical just now. I used Leonardo AI, with the style Leonardo Lightning and substyle Creative, and Aspect Ratio set to 16:9, to produce images sized 1368x768 pixels. It didn't take long to find that the ratio was off a bit: 57:32. What's going on?

All art generating programs produce images that are made up of square blocks. In this case, the blocks are 24x24. There are a few ways to get 16:9, or 1.77777…, from 57:32, or 1.78125. However, I am a purist, so I want the vertical dimension to be a multiple of 9, and better yet, I decided to restrict images to multiples of 18 pixels high, and thus, also having horizontal dimension the same multiple of 32.

Considerations Regarding File Locations and Naming

Whatever program I use, when I download the image, it is put in the Downloads folder. Thereafter I do any work on the file, which may be several steps through intermediate files, in the Downloads area. Sometimes I use folders under Downloads to keep things organized.

Whichever program I use, right after I download it I rename the file. I have two ways depending on the length of the prompt.

Short Prompts (less than ~120 characters)

From a recent project: 

IFX 250203-08 Two naturalists and two medium-sized dinosaurs sitting together at a table having tea and croissants, digital art

This image was produced by ImageFX on the date shown (a few days ago), and is the 8th image I made that day using ImageFX. This prompt is 113 characters, a bit longer than usual, but it doesn't make the file name overflow the namespace in the disk's file system.

Long Prompts

I keep a file of long prompts, dated and labeled. The image above has the file name Leo 241108-03 LLightning Creative Prompt 241108-02, Cave Office

This was produced by Leonardo AI using Leonardo Lightning style and Creative substyle; the rest of the file name identifies the prompt.

If I have just one or two files I'm working on, I do so individually. Otherwise I use batch mode.

Convert Files as Needed

All but one of the programs I use produces files that are smaller than 1920x1080. Gemini produces only square images 2048x2048. I'll show how to deal with that later. For all the others I use Upscayl to make the image larger and sharpen it.

One caveat with Upscayl: although it will make a valiant effort with a PNG image, the resulting image is monochrome (gray), so I first convert PNG files to JPG, for which I use IrfanView, also in batch mode if I have more than two images. Furthermore, image files produced by ImageFX have a JPG extension, but they are PNG files. I open them one at a time using IrfanView (it can quickly skip from file to file, so this isn't too time consuming). Before opening a file it asks if I want the extension corrected. I click "Yes" and continue. Then you are ready to convert these to JPG.

DreamStudio also produces PNG files. They need to be converted. The following image shows the IrfanView batch edit screen:


Here are the steps:

  • Select Batch Conversion at top left
  • Select JPG as the output format
  • Select the output folder at middle left (I already made a folder named OutPix under Downloads). Next column:
  • Select the input folder at top right (I already put all the files to be converted into a folder named PNGPix under Downloads).
  • Select PNG as the input format (file type).
  • Highlight all the files and click "Add".
  • Click Start Batch at lower left.

This will convert the files and put them in the folder OutPix, ready for upscaling.

Upscaling

For upscaling an image by 2x, 3x, or 4x I use Upscayl. It has several upscaling models. I usually use FAST REAL-ESRGAN, which takes about ten seconds to convert a ~1K image on my computer. When I want ultimate quality from a highly detailed image, I use REMACRI, which takes about two minutes per image. Upscayl has a batch mode, which works on a folder at a time. 

This is the screen that appears when you set Upscayl to batch mode:


Here are the steps:

  • Step 1, I put the files to upscale into a folder called OutPix that is in the Downloads folder, as noted above. This would include files from programs that produced JPG natively.
  • Step 2, select the model and ratio (2X in this case)
  • Step 3, I choose the Downloads folder. I work in the Downloads folder because files there don't get backed up to OneDrive. That lets me work and then clean up, followed by putting the files I plan to keep in their final folder(s) later.
  • Step 4, click Upscayl to start the process. 

For the 14 files shown, this model ran a little more than two minutes. Had I used REMACRI, I could go get a snack: it would take half an hour.

Image Sizes in Each Program

IrfanView has a wonderful item in its Edit menu: "Create maximized selection (ratio:)" with a caret off to the right. Click that to see available ratios. You can add any ratio you like by using the prior Edit menu item: "Create custom selection...". 

If you have an image, for example, 1920x1200, that you want to crop to 1920x1080 (and there is headroom or footroom to do so), you can click this option, then the caret, then the 16:9 item, and cut lines will appear. You can use the up or down arrows on the keyboard to slide the selection, then CTRL/Y to crop the image. Save with a new name.

Dall-E3

1024x1024 → 1792x1024 (1.75:1=7:4). You initially get four square images. Click an image to work with it. There is a button "Resize" with a "4:3" option. It actually produces an image close to 16:9 but not quite. The image is similar to the square one, but not the same, and it can be quite different.

Process: Upscale by 2X to 3584x2048, then crop to 3584x2016.

DreamStudio

There are two Stable Diffusion models. In either case, there is a setting to modify the pixel count. Only DreamStudio can do this at present.

  • Stable Diffusion v1.6 with 16:9 selected sets the size to 910x512 (1.7773:1=455:256); reset to 896x504, which is (16x9) times 56. Then upscale 3x to 2688x1512.
  • Stable Diffusion XL v1.0 with 16:9 selected sets the size to 1344x768 (1.75:1=7:4); reset to 1344x756, which is (16x9) times 84. Then upscale 2x to 2688x1512.

Gemini

2048x2048. Negotiate by asking for "wide format" and possibly tinkering with the prompt until there is sufficient headroom and/or footroom to crop to 2048x1152, which is (16x9) times 128. No upscaling is needed.

ImageFX

1408x768 (1.833:1=33:18). Upscale 2x to 2816x1536, and then in IrvanView use the Resize function to get 2805x1530 and (using the Edit subfunction) crop to 2720x1530, which is (16x9) times 170.

Leonardo AI

At least one style mode produces a larger size.

  • Most styles produce 1368x768 (1.78125:1=57:32). Upscale 2x to 2736x1536, resize to 2725x1530, crop to 2720x1530.
  • Leonardo Phoenix produces 1472x832 (1.769:1=23:13). Upscale 2x to 2944x1664, and then crop to 2944x1656, which is (16x9) times 184.

There are some other methods one can use. For example, for a Dall-E3 image that is 1792x1024, you could use the Resize function in IrfanView to produce 1920x1097, and then crop it to 1920x1080. The Resize is only by 7%, so it produces an image with a good appearance. You can also crop out a 1920x1080 image from a Gemini image. A lot depends on the image you are working with.

Signing the Image

Style of Signature that I use

Having several different image sizes, it's a bit tricky to add a signature to an artwork that is of a consistent size. I like to use a signature in two or three parts. The more usual two part signature, using my first two initials plus last name, is like this:

OK Myname / Dall-E3 2025

For an image I produced this year using Dall-E3. I use abbreviations for the others:

  • DreamS = DreamStudio
  • Gem = Gemini
  • IFX = ImageFX
  • Leo = Leonardo AI

Sometimes an image is part of a series, such as the Cave (Troglodyte) series. Then I'll use a 3-part signature on two lines, such as:

OK Myname / Dall-E3 2025
Cave Master Bedroom

I set the second line to a smaller type size, typically about 0.7 of the first line.

Size and Placement

Most images have an area near lower left or lower right where a signature can be placed. I use the Paint dialog (F12 key) and select the "A" for text input. The cursor becomes a little plus that shows where the lower left corner of the first line is to go. Using a signature on the right is harder because it's often hard to tell how long the text is going to be. 

The greatly differing image sizes mean it is best to use corresponding type sizes. After some experimentation, I settled on using this basis: 14 points for an image 1988 pixels wide, which is suitable for images with horizontal dimensions from 1920 to 2194. This grows to 28 points for the range 3840 to 4114. This table shows the sizes I use:


This is a picture because tables are hard to produce in Blogger. The Paint/text tool's list of type sizes is all even numbers, but you can type in an odd number. All I can say is, experiment with it to find out a procedure that you like, or can live with.

Color

I looked at paintings by several artists. Some use a black signature, but many use a color from elsewhere in the painting that contrasts with the area of the signature. I like this method. The Paint tool has plenty of flexibility in this regard.

Font

Many years ago I designed a few fonts for a project. One of these is a strongly-weighted Sans Serif font that I like, so that's what I use. The Paint/text menu lets you select any installed font.

This isn't wholly comprehensive, but I hope it is enough to get you started turning generated art projects into wallpaper for your computer screen(s). Also, whatever art you produce, if it's for the public to see, signing it is a good idea.


Wednesday, July 29, 2015

Numeracy instruction

kw: book reviews, nonfiction, mathematics, mathematical thinking, instruction, learning methods

When I saw A Mind for Numbers: How to Excel at Math and Science (Even if You Flunked Algebra) by Barbara Oakley, PhD, I was intrigued. The main title was in the form of a cutesy equation, which I supposed was the editor's conceit. Having read the book, I am not so sure.

Dr. Oakley knows what she is talking about, because she began as a math-phobic, but learned to love it. Throughout the book she has 1-page items by people with a similar background, who now are comfortable with mathematics, at one level or another.

The book is a breezily-written compendium of learning techniques and tips gathered into 18 chapters. It is not intended to be taken in wholesale. Different people learn in different ways, and in many cases, a single chapter, or even one point in a chapter, can unlock the math potential for someone. But I wonder…

At a certain level, to be human is to be mathematically adept at some level. Very young children, asked to choose one of two piles of coins, will pick the one that is spread out rather than a neat stack of the same number of coins. They equate spatial area with quantity, and don't realize that the two piles are equivalent. But, I suspect they have not yet learned to count, and it takes this further level of sophistication before they have the mental equipment to fairly evaluate the two piles.

I think that is analogous to an experience I had at about age 12. Someone had showed me a few Algebra equations. I saw something like 10x=5 and wondered, "How can that be?" I thought the "x" was supposed to represent a digit, like the stuff on the left would be a number from 100 to 109. So I thought something else had to be going on. This caused quite a delay in my getting the point when I began Algebra class later that year. But I think, a month or so into the school year, when it all began to "click", that my brain had simply grown up enough to have the right tools for doing algebra.

We all do a certain amount of calculation. Most of us can quickly evaluate the change we're given at the store (if we used cash). People who bowl soon learn to keep score without writing down their calculations. When we drive (without a GPS), and we see "Chicago, 95 miles", we check the odometer, note what it shows, and can then glance at it later and know how many miles we still have to go. Many times, we can even be told a "problem" like this:
John and Mary ride bicycles toward each other at 5 mph, from 1 mile apart. Their pet bird, which flies 20 mph, flies back and forth from one to the other until they meet. How far does the bird fly?
Most of us, by age 10 or so, can figure that John and Mary each ride half a mile, because they are going the same speed. The bird flies four times as fast as either of them, so its total flight is two miles. This kind of "figuring" is actually algebra, without the equations. In fact, it would take me longer to write down the equations for solving this using "traditional" algebra, than it did to write the two sentences above. What is funny is when someone tries to tackle the problem as a series of flights of decreasing length by the bird. The equations to get that to work are gnarly!

So every one of us has some amount of math built in. Standard equipment. But that "some amount" varies a great deal from person to person. Not everyone can learn algebra, no matter how it is taught nor how hard they try. But most can, and by "most" I mean "more than half but not a great deal more". Some kids who had no trouble with algebra never, ever get the point of Trigonometry. My senior year of high school, we got done with the ordinary curriculum for the year a few days early, so the teacher did an experiment. He got out a few copies of a basic text in Calculus and taught it to us. In just a couple of weeks, I learned enough Calc so that I pretty much breezed through the Calc 101 course the next year in college, which used that same textbook!

I was a working mathematician, at a certain level, for decades. But there are branches of math that have never made sense to me, and others that I can puzzle out with desperate levels of effort. I had to take Differential Equations three times to pass it. I'm still not comfortable with it, but the explanation of how to use it takes only two pages in my old CRC Handbook of Chemistry & Physics, and actually contains most of what one needs to do nearly any Diff Eq problem!

And so it goes. Each human brain has a certain mathematical limit. With luck, we might grow mathematically to our full potential, but it is time consuming. Most of us never need all that stuff. But we also grow into certain abilities over time. Just as the brain doesn't finish emotional maturation until about age 25, it must be true that certain math circuits only get set up at certain ages. It may be that the ten years between my second and my third try at learning Diff Eq made more difference in my ability, than the exposure I'd had during the first two attempts.

With all that in mind, I find no sense in delving into what Dr. Oakley has to say. The book is a fantastic resource. Someone who needs encouragement and help in how to learn math and science will do well to read the book quickly, then return to read over certain sections with more care: those sections that seemed to make the most sense the first time through. The first two chapters will be helpful to everyone. As for the others, while the author attempts to make them generally applicable, each will actually be best suited to people with a certain kind of mind, one way or another.

Friday, September 14, 2012

Guitar Tuning - harmonics plus tweaking

kw: music, musical instruments, instruction

I played guitar for forty years before I obtained an electronic tuner. At first, I kept my guitar in tune by ear using the piano; my mother was a fine pianist and our piano was kept in tune. Before going off to college, I got a tuning fork, the A-440 one. I learned to tune the A string by sounding its 4th harmonic, striking and setting the fork, and tuning for zero beats. Then I tuned the rest of the strings using harmonics, which I'll describe shortly.

As my ear got keener, I noticed that tuning with pure harmonics led to certain chords, such as D, not sounding quite right, and I tinkered with the tuning a lot before I learned more about what I was doing. Finally I learned enough about equal temperament and how the harmonics relate to it to get my guitar tuned right, no tinkering needed.

This fingerboard diagram, the first octave cropped from a larger illustration in Wikipedia Commons, shows how the 3d and 4th harmonics relate everywhere but between the G and B strings:
The Nut is on the left, and the bridge would be off to the right a distance equal to the width of this image. The harmonics at the 7th fret (the rightmost set of orange dots) are the 3d harmonics, and those at the 5th fret are the 4th harmonics. You produce a harmonic by very lightly touching a string above the fret, being sure not to depress the string, and plucking the string near the bridge, preferably pretty close. The closer you pluck to the bridge, the greater the amplitude of higher harmonics. The 4th harmonic is strongest when you pluck 1/8th of the way up the string from the bridge, or about 3.2 inches (80 mm or so). This is also a good place to pluck for a strong 3d harmonic, which avoids having to adjust when you are trying to get two strings to sound on different harmonics so you can hear if they are in unison, or nearly so.

"Nearly so" is very meaningful in this context. This table shows why. Note first that the 4th harmonic of the A string is 440 Hz when it has been tuned to the tuning fork. Now, when the D string is in proper tune according to equal temperament, its 3d harmonic is almost half a Hz higher. By the same token, the 4th harmonic of the low E string is almost 0.4 Hz lower than the 3d harmonic of the A string, when the E is properly tuned.

Early on, I would tune to exact harmonics, using the A string to tune the E and D, then the D to tune G, the low E to tune the high E', then the high E' to tune the B. Working out the math, we find that with A at 110 Hz, the two E strings are then 82.5 and 330 Hz, the D is 146.67 Hz, G is 195.55, and B is 247.5 Hz. We'll see in a moment that tuning a pair of strings to harmonics this way results in the lower string being 2 cents sharp with respect to the higher string. A "cent" is 1/100th of the halftone interval. Thus if E and E' are 2c sharp, B becomes 4c sharp, while D is 2c flat and G is 4c flat. Thus the G-B interval is off by 8c.

One would think that these little errors, which amount to fractions of a Hz, would be too small to hear. Not so. An error of one musical cent or two is not easy for everyone to hear, but almost anyone can hear an 8c mistuning. This table shows the frequency and cent differences, string pair by pair, and how I compensate for them:


As you can see, for the lower strings, the frequency differences are less than 1Hz, so it is hard to adjust by counting beats. In my experience, I cannot hear the beat when it is less than 1Hz, and I can barely hear the B4 to E'3 beat. What I do, then, is adjust until there is a difference I can barely detect. For example, I first tune the low E to the A using E4 and A3, and get it exact by nulling the beats. Then, knowing that the E is a tad sharp, I flat it until I can just detect the difference. I do so for each pair. This procedure leads to a final tuning so close to equal temperament that the G and B sound good together, and the chords D, A, C and E all sound equally good.

Of course, now that I have an electronic tuner, I can get a guitar in tune pretty quickly, but I have found that the green light stays on over an interval of plus-or-minus a cent or two. Thus, after I tune electronically, all the strings are probably within a cent or so of being right, but if I tweak a little by ear, I can make my guitar sound just a little bit better.

One caveat. This does not take inharmonicities into account. Because of small nonlinear effects the harmonics are slightly sharp compared to the open note, but for a guitar using steel strings the difference is half a cent or less at the 4th harmonic, and negligible at the 3d harmonic. Nonetheless, the result is a slight stretch of the tuning. You may know that pianos are usually stretch tuned, and over the 88-key range, the highest notes are 10-15 cents sharp as compared with the lowest notes. Piano strings are stretched tighter than guitar strings, and the harmonics get sharper as a result. Stretch tuning makes notes a few octaves apart sound better together. This is also true for the guitar, in principle, but it is very rare to play notes more than 3 octaves apart on the guitar. I haven't found a noticeable difference.

Monday, September 15, 2008

Making that picture perfect . . . in size

kw: methods, instruction, image optimization

This tip is too good to pass up. There is a little, unobtrusive icon in the Picture toolbar in the Microsoft Office products, which I only noticed recently. Though I've been using Office 2003 for five years, it simply escaped my notice. When your mouse cursor hovers over the icon I have highlighted here (the tenth), a hint pops up: "Compress Pictures".

In the past, based on advice I received a decade ago or more, I'd pre-optimize all the images I was going to use in a PowerPoint or Word document by changing to a resolution consistent with the final purpose (print or projection) and using either GIF or JPG compression to minimize the number of bits needed to store the image once it was embedded.

As a side note for those who need it: GIF uses run length encoding, so it is best for images such as screen shots or graphics such as those produced by Visio or a CAD program. JPG uses fourier series optimization, which drops out more detail as you use a smaller "quality" criterion. A "quality=90%" JPG looks as good as either a GIF image or an uncompressed (BMP, for example) image. However, for most screen shots the GIF version will be smaller, while for most photographs the JPG will be smaller.

The screen shot above is 416x63 pixels, which would take about 26 Kbytes to store as an 8-bit BMP file and three times that much for a 24-bit BMP. As a JPG file it is 10 Kbytes, and as a GIF (which I use here) it is 7 Kbytes. The GIF file for the image below has even better compression, because there is less detail: an 8-bit BMP would require 145 Kbytes, but the GIF size is 11 Kbytes.

I couldn't resist trying out the idea with a slide show I was planning. I started with images from my digital camera, some cropped. The uncropped ones were 1.5 Mbytes in size, and at 3000x2000 pixels, much too large for projection or printing once embedded in PPT slides. Even the smallest crops were close to a Mbyte each. The final file size was 27 Mbytes, yet it has only 25 slides! I first made a print version. Clicking on the Compress Pictures icon yielded this dialog box:

The default setting is for Print resolution. I changed only the first item, selecting "All pictures in document", and left the resolution at Print (200 dpi). I saved the result with a modified file name.

An image that sits nicely into a titled PPT slide is about 4x6 inches (around 10x15 cm), so at 200 dpi such a picture would need only 800x1200 pixels. That alone reduces the number of pixels by a factor of 6.25. The resulting file's size is 4.5 Mbytes, about 1/6th the size of the original file.

Then I redid the compression using Web/Screen resolution, which is 96 dpi. The number of pixels to be stored is now 1/27th of the original. Saving with yet another file name, I saw that the file size is now 1.3 Mbytes. This file, when projected, looks as good as the Print-resolution version (and the orignal), though there is a difference visible when pages from the two files are printed.

Next I tried this method with a large Word file I've recently been asked to edit at work. It is humongous: 100 Mbytes, yet is only 54 pages, and has 57 screen shots. Looking at them, I could see that they were pasted in, and had probably not been saved first as a file or otherwise optimized. They are mostly 1024x768, 24-bit screen shots. I tried Compress Pictures, and Print resolution (the document is intended for printed use). Guess what? No help whatever. The new file was just as large as before!

I tried another method I'd heard of for finding out which images in a Word file are too large. I saved it as HTML. Amazingly, all the images were modestly-sized. None were larger than 150 Mbytes. So I did the dumb-luck thing and re-opened the HTML using Word, and saved the whole mess as a Word file. The new file is 2.6 Mbytes!

When a Word (or other Office) file is saved as HTML, all embedded objects are saved as separate files in a subdirectory with a name derived from the document's name. That is where the images were put. Some were GIF, most were PNG (similar to GIF but some files compress better that way), and a few were JPG. The HTML conversion does optimization of its own. In this case, the final compression factor is about 50. I don't know why. I don't plan to go to the work to figure it out, either. That'd be looking a gift horse in the mouth.

I have since used the Compress Pictures to save space for several files, and I'll keep the to-and-from-HTML method in reserve in case I get another pathological file.