2025-02-02

PaintShop Pro - Color eyes with masking

 PaintShop Pro - Color eyes (color change), using masking


Goal:
Change an eye-color using PSP's Mask feature.
In the photograph, anything's color can be changed with this technique.  For example, a bridge or a river
.

This can be better than PSP's "Color Changing Tool".  Instead of "repainting", this adjusts the hue and saturation, without losing details in the object

Documenting the steps in a more succinct place than a lightning-fast AI-generated found on YouTube video. I must have watched that video 47 times to slow it down.  The steps here are easier to follow, with better details.  Eye-model art work from that video.

Using PaintShop Pro 2023
These steps should work with any version and these rough steps will probably work in any photo editor.

Steps:

1.  In the layers pallet, duplicate the background layer
 
Rename the new layer to something like "myMaskedLayer" by right-clicking the new layer's name in the Layers Pallet.

2.  Highlight the new (duplicated) layer

In the Layers pallet, click the Mask icon
Choose "Show All"

A new group forms
Note the new White Mask sublayer

3. Add an HSL Adjustment Layer

In the new Mask Group, select the inner full-color photograph (illustrated below, in Blue)
(For now, ignore the white Mask layer)

On the bottom, click the Layer's "Adjustment Layer" icon (bottom of pallet)
Select menu "Hue/Saturation/Lightness" (HSL)

4.  An HSL popup appears

A new gray-scale image displays
Check [x] Colorize

Note:  All sliders move to zero
Click OK

5.  Select the White Mask Layer


In the Color Pallet's menu:
- Set the Fore-Color to Black (click the black/white diagonal button)
- Set the Back-Color to White

6.  Paint the eyes

While still on the "White" layer

Select the PaintBrush tool
Set Hardness = 0
Opacity = 100
Size = (Any comfortable, but smaller brush size)

7.  On the gray-scale "white" layer, paint the eyes with a relatively small brush. 

- Use the mouse's roller-wheel to zoom
- Zoom in 1000% is common

You are essentially painting the eyes with a black brush, but since this is on a masked layer; the background color bleeds through


When done, note the white-layer's eyes, showing as two dark eyes on a snowy-white background:

8.  Invert the layer

While still highlighting the "white" layer
Select top-menu:  Layers, "Invert/Mask Adjustment"

The photo returns to normal colors
(The "white" layer, with its two little eyes is now a "black" layer with two white eyes (not illustrated))

9.  Select the HSL layer

Right-click, "Properties"
Adjust the slider-bars until happy

At the group's level, toggle the layer's "Visibility" icon off/and on to see the effect:

10.  Optional: Adjust the effect's lightness

While highlighting the HSL Layer
Select the Pallet's bottom button "New Adjustment Layer"
Choose "Curves" from the sub-menu (not illustrated)

Slide ("scootch") the two sliders inland a "smidge"

Final results:

-end

2025-01-31

Powershell - ParseExact with 3 argument(s): String was not recognized as a valid DateTime

Powershell Code - ParseExact Date Conversion - String not recognized as valid DateTime


Windows Powershell

Goal:  Read and validate a string-date (with a known and expected format). 
Guarding against February 31st and stuff like that

Technique:
Cast the string into a [datetime].
Use ParseExact to convert the date
Use try-catch to detect detect failures.

Code:

[DateTime]$dtconvertedDate           #Declare DateTime Variable
[string]$strmyDate = "01/01/2025"    #Variable to test

try
{
   # Cast the ParseExact as [dateTime]

   # Unsafe
   $dtconvertedDate = [datetime]::ParseExact($strmyDate, "MM/dd/yyyy", $null)

   # Safer
   $dtconvertedDate = [datetime]::ParseExact($strmyDate.Trim(), "M/d/yyyy", $null)
}
catch
{
   # not illustrated -- not a date
}

Possible errors:
Exception calling "ParseExact" with "3" argument(s): "String was not recognized as a valid DateTime."

Possible answers:
-  $strmyDate  is from an Excel-exported CSV or tab file.   Be sure to .Trim().  Unsafe otherwise.

-  Mask  "MM/dd/yyyy" is case-sensitive!

-  Mask "MM/dd/yyyy"  can be, but is not always safe. 
    Date strings with leading zeros vs not:  "1/17/2025" -- MM/dd will fail.
    Use "M/d/yyyy"

-  Mask in wrong format:  MM-dd-yyyy  vs MM/dd/yyyy
    hyphens vs slash.  ParseExact with a mask cares.