Photo editing with the GIMP: Rounded corners Part III

Posted on

Edit Dec 6, 2009: I have also done a demonstration of one way to make only one, two, or three corners round, in “GIMP: Combining selections.”  In it, I used the method of Part I to make a rounded selection, and then I added the desired square corners to the selection.

What?  Another post on making corners round in the GIMP?  Yes, that’s right.  Making round corners is very important and deserves a thorough treatment.

I’m kidding.  This time, the aim is a simple demonstration of a tool that has many uses once you’ve mastered it: layer masks.  So you could call this Part III on rounded corners, or Part I on layer masks! (Here’s an entry in the GIMP manual on layer masks.) Quick summary at the end.

In Part I and Part II, I demonstrated a couple of the GIMP’s built-in ways to make corners round: deleting everything outside a selection that’s the shape of a rectangle with rounded corners; and running the “Round Corners” filter, which does that and a bit more automatically.  These are both so quick and easy that if rounded corners were really my aim, say for graphics for my web page, I wouldn’t be looking for anything else.

When I first started using the GIMP, it wasn’t obvious to me what the point of a layer mask was or how to manipulate one.  But once I’d made the effort to become familiar with them, I was relieved to find that they were actually not that mysterious, or complicated, after all.

I got a bit tired of staring at my little Gatekeeper butterfly though (not the butterfly’s fault: I just looked at it for too long), so I’m going to use flowers this time.

Say we have a picture like this:

Dicentra spectabilis 'Alba,' I think.

It’s called Dicentra spectabilis ‘Alba’ (bleeding heart), according to the BBC Gardening website.

I didn’t plant it, and it’s no thanks to me that it’s still alive.  That goes for everything in our garden.

OK, now pretend we want to put round corners on this using a layer mask.  We’ll have to know what a layer mask is and does first…

The layer mask is a greyscale image you can make and apply to any layer in your image file.  As its name suggests, it masks the layer: it changes which parts of the layer can be seen, and which parts are invisible.

The principle is this:

Where the layer mask is white, your layer is visible.

In any region where the mask is black, the pixels of the image layer become transparent, and you can see through it to the layer below.

Any level of grey in between corresponds to a level of partial transparency.

It’s pretty easy to imagine doing all sorts of complicated things with this, but for now I’m sticking to my rounded corners.

As soon as you remove or disable the layer mask, you can see the whole image again.  This is one of the beautiful things about layer masks: they’re non-destructive.  This means it’s easy to try a lot of variations without having to make too many memory-consuming copies of your target layer or rely heavily on multiple “undo” levels.

Now to business.  As in Part I, I’m going to select a rounded rectangle to begin with (right-click on image; Select -> Rounded Rectangle).  I choose “radius” 20% (remembering this is actually the diameter of the curve it will make).  Now I have a selection in the shape of the image I want to end up with, like I did in Part I.

shot27Where I take a left turn relative to that, though, is that I now go to Select -> Save to Channel.

What that does is save the selection into a greyscale image in a place that’s easy for me to get at when I want to make it into a layer mask.  In this channel, whatever was inside the selection will be white (visible), and whatever was outside will be black (masked out).  If your selection was feathered, there would be a smooth transition from white to black, i.e. the mask you’ll eventually make would grade the image smoothly from visible to transparent at the edges.

shot28

Now if I go look in the Channels tab, I see a new channel called Selection Mask copy. Incidentally, if the Channels dialog is not showing, you can bring it up by doing: right-click; Windows -> Dockable Dialogs -> Channels. Any dialog you want to see can be brought up in a similar way.

The channel name is easy to change if you think you may want to have more than one and want to keep them straight: right-click on it in the Channels dialog and choose Edit Channel Attributes and give it whatever name you want. Renaming a normal layer works like this, too.

shot29
shot30

At this point, you may (like me) be wondering what “Fill opacity” refers to in the Channel Attributes dialog. That parameter has to do with how the channel looks if you make it visible over the image layer by clicking over to the left of it (in line with where all the eye icons are next to the Red, Green, and Blue channels).

I’ll demonstrate that in a sec, but first let’s click on the box at the right of the Channel Attributes dialog, the one that’s filled in black in the upper-left half.

shot31

This brings up the colour editor.   I’ve clicked at the top right corner of the colour box to select the colour red.

(Aside: Kindly notice that this dialog is called “Edit Channel Colour.” That’s because I have asked my Mandriva Linux system to use Canadian English. Nice, eh?)

shot32

This is what the Channel Attributes dialog looks like now. If I were to slide the “Fill opacity” slider to the right or left, the red in the lower-right corner of the box would get more or less opaque.

shot33

Now if we click to the left of the Selection Mask copy channel in the Channels dialog, an eye icon appears, indicating that the channel is visible….

shot34
…and the black regions in the channel show over our image as 50% transparent red. The red helps make it more visible than if I’d left it black, and the transparency lets you see what the mask will cover in the image.

You can leave the “eye” there and have the red corners showing, or click on it again and make the channel invisible. I’ll make it invisible at this point.

We still don’t have a layer mask, do we? That’s because I digress a lot.

Just one more thing before we get to the point. Prepare a white background layer: go into layers dialog and add a new one, fill it with white, and drag it so it’s underneath the image layer (like in Part I). You wouldn’t do this step if you wanted the corners to stay transparent instead of white.

shot36
Then, finally, make the layer mask: right-click next to the image layer, and choose Add Layer Mask (this is also available in the main menu accessed by right-clicking anywhere in the active image: Layer -> Mask -> Add Layer Mask).

shot35
This brings up a dialog that gives us the option (among other possibilities) to populate the layer mask with a channel. So select the channel we made before and click Add.

shot37

The layers dialog now looks like this.

Next to the little cartoon of the image, there’s now a little cartoon of the contents of the layer mask.  You can right-click on this and check or uncheck “Show Layer Mask” to toggle the main image window between the image and the mask, or “Disable Layer Mask,” which removes its effect without destroying the layer mask. Left-clicking on it, which is the same as “Edit Layer Mask,” makes it the thing you’re actively editing with any tools you apply (whether you’ve made it visible or not), so you have to remember to left-click on the image icon (or uncheck “Edit Layer Mask”) to edit the normal layer again.

And the image now looks like this:

beep2009-00-round

Boom, we’re done. Well, almost. Once you’re sure you’re happy with the masking you can right-click on the layer in the Layers dialog and choose Apply Layer Mask (or do Layer -> Mask -> Apply Layer Mask). Before saving as JPEG, I did Image -> Flatten Image. I tried saving as PNG, without the white background layer, and GIMP gave me the option to flatten or to merge visible layers before exporting. I chose to merge the visible layers, and the resulting file has nice properly transparent corners.

To sum up:

1. Make a selection in the desired shape (here, rounded rectangle).

2. Choose Select -> Save to Channel

3. (Optional) Make a white background layer and drag it below the image layer

4. Choose Layer -> Mask -> Add Layer Mask; “initialize” it to the channel with your prepared mask in it.

5. Choose Layer -> Mask -> Apply Layer Mask

6. Image -> Flatten Image or Image -> Merge Visible Layers

7. Save with a different filename (don’t overwrite your original photo file).

This was about the simplest layer mask you’ll ever see, and there are many ways to generate layer masks — including painting with the painting tools.  The possibilities are endless.

I think I’m finished with rounded corners for now.  Can’t guarantee about the layer masks.

Happy first birthday, G!

Posted on

Birthday cake

Well, now G is one year old.  A year!  How did my little tiny baby turn into a one-year-old so fast?   Don’t answer that.

It’s been a long year, and a short year.  Many of the hours passed excruciatingly slowly.  The whole thing went by in the blink of an eye.  If we hadn’t had her, everything would probably look just about the same as it did a year ago, maybe two years.  We’d have slept more, learned less.  We’d have fewer dilemmas.  We might be more sure that there must be a satisfactory way for careers and children to coexist, even if it wasn’t obvious to us what it was.  We’d have laughed much, much less.  We’d have missed out.

Before G, I didn’t see what people saw in babies and small children.   Now I know babies are incredible and awesome.  I fully expect to learn that this is also true about small children in the very near future.

Happy one year, our little G.  We’re so proud of you.

gbehindbed

More on the Panasonic LX3 and Linux

Posted on

I’m getting some search engine referrals to do with the Panasonic DMC-LX3 and Linux since I wrote about my trepidation over upgrading the LX3’s firmware, and, well, I don’t have much up here on the topic.  I guess (but I may be wrong) that the main thing to talk about is how to get the pictures from your LX3 to your Linux box if you’re not using a card reader.  Is that uploading (from the camera), or downloading (to the computer)?  I’ve always thought of it as uploading, but that’s neither here nor there.

Uh, skip at least a paragraph from here if you’re interested in that topic without a lot of rambling in between.

Actually, it’s been my habit to just use a card reader <memory lane> since my Canon Powershot A40 and its 128MB CF card.  We had an aging Pentium II running Windows 95 and USB support was not great on Win95, but I found a Sandisk CF reader that worked with it.  It was not long after that that I bought my first ever computer (piece by piece) and didn’t feel like I had money left over for Microsoft, and thus came about my first rendezvous with Linux. </memory lane>

Man, do USB storage devices work better in Linux now than they did then!  And man, do the RAW files from the LX3 take up more space than the JPEGs from my 2-megapixel A40!  But those old pictures are still great and they really bring back the memories in vivid colour!

OK, so my point…oh yes, it was that I was always worried that a transfer would go wrong due to running out of battery power on the camera, so I always used a card reader.

However, I think that when I bought the LX3 I wasn’t aware that my multi-card reader didn’t do SDHC, and so I had to do at least one transfer directly from the camera.  And I remember having to try it a couple of ways to get it to work; I just don’t remember what I tried and what didn’t work.  However, for fun, and with the manual handy, I tried it again yesterday (having finally located the particular USB cable I needed for the LX3; I seem to have a dozen USB-to-mini-USB cables lying around and only a single teensy-tiny-ended one that fits this camera).

Jumping to the end, in case you’re here looking for actual information: it worked fine with the settings I had.  I’m guessing that the relevant one to find is USB MODE, on the fourth page of the SETUP menu (found by entering the menu starting in playback mode and selecting the wrench at the left-hand side):

USB mode option on LX3 in setup menu

I had PC selected, which worked for me.

lx3usbscreen2

Sorry for the distortion on the screenshots.  I took those with another camera.

I’m running Mandriva 2009.1 on this computer, but I’d guess (and hope) that as long as your distribution is reasonably new, it should handle the DMC-LX3 as a storage device just fine.

The play-by-play:

  1. I turned on the camera in playback mode.
  2. I plugged in the special tiny usb cable to the camera (OK, I also connected the other end to the computer).  The relevant connection is “AV OUT/DIGITAL” — the middle one — as illustrated in the manual (Page 113 in mine).
  3. The camera display read, first: “USB MODE;” then “CONNECTING TO PC;” then  “ACCESS;” then for the rest of the exercise it displayed just a zigzag arrow in a box.
  4. Mandriva noticed it was there and “LUMIX” came up in the device manager.  I opened up the file manager (Dolphin, but that’s not really relevant here).
  5. I copied my pictures.
  6. I unmounted (“safely removed”) the LUMIX device, then disconnected the cable from the camera.

This was a handy exercise for me, because there were images in the camera’s internal memory from months ago that I’d forgotten about, and I remembered them when I read the line in the manual: “Remove the card before using the pictures in the built-in memory.”  And now the built-in memory has space again for the next time I grab my camera to catch some moment and forget that the card’s still in the card reader!  I see in the manual that photos in the internal memory can be moved onto the SDHC card using the COPY option in the playback mode menu, so even if I can never find that USB cable again, I should always be able to use a card reader to get my photos onto the computer.