Judge a book by its cover Overview

The cover of a book will be provided in the following ASCII format:

______
|    |
|    |
|    |
|    |
------


The input can be in any reasonable format (eg. a list of strings, a nested list of characters, etc.)

Inside the "borders" of the cover, other printable ascii characters might appear, which contribute to the "popularity index" (the definition of which has been completely made up for this challenge).

Popularity Index

Let the popularity index of a book be the number of unique characters that appear on the book cover (this does not include space characters or the edges of the cover). A book may have no unique characters on the cover (the cover is blank), in which case the popularity index is 0.

Examples

______
|\/ /|
|/\/ |
| /\/|
|/ /\|
------


Two unique characters (/ and \) so the popularity index is 2.

______
| / /|
|/ / |
| / /|
|/ / |
------


One unique character (/), so the popularity index is 1

______
|    |
|    |
|    |
|    |
------


No unique characters, the popularity index is 0

______
|\^$@|
|/\/ |
| 456|
|/ /\|
------


8 unique characters, so the popularity index is 8.

______
|\^$@|
|987 |
| 456|
|/hi!|
------


14 unique characters, so the popularity index is 14.

______
|////|
|////|
|////|
|////|
------


One unique character (/), so the popularity index is 1.

Damaged Books

The edges of the book might also be damaged:

Top         Left        Right       Bottom

_~____      ______      ______      ______
|    |      |    |      |    |      |    |
|    |      |    |      |    |      |    |
|    |  or  {    |  or  |    }  or  |    |
|    |      |    |      |    |      |    |
------      ------      ------      ---~--


The book may have several of these "scratches". The scratches at the top and bottom will always be represented by a ~, while the scratches on the left and right will always be represented by a { and } respectively. Each scratch will decrease the popularity index by 1. 

As a result, it is possible for a book to have a negative popularity index.

Task

Given an ASCII representation of a book cover in the format described above, determine the "popularity index" of the book

Assumptions


You can assume that the characters |, _, and - will not appear elsewhere on the book cover (only on the edges). However, the scratch characters ({, }, and ~) may appear on the book cover in which case they should be treated as any other unique character on the cover.
All characters appearing on the cover will be printable ascii
Note that spaces do not count as a unique character. As the examples above show, a "blank" cover is one that only contains spaces.
The book will always be the same size (height and width are fixed). Hence, the popularity index will never exceed 16.


Scoring

This is code-golf. Happy golfing!

More Examples

______
|{. }|
|/. /|
|/. /}
|/. /|
------


4 unique characters ({, }, . and /) and one scratch (} on the right) so the popularity index is 3.

______
{    |
| .. |
|    }
{    |
--~~--


One unique character (.) and 5 scratches so the popularity index is -4.

Test Cases

______
|    |
|    |
|    |
|    |
------    -&gt;    0

______
|\/ /|
|/\/ |
| /\/|
|/ /\|
------    -&gt;    2

______
| / /|
|/ / |
| / /|
|/ / |
------    -&gt;    1

______
|\^$@|
|/\/ |
| 456|
|/ /\|
------    -&gt;    8

______
|!!!!|
|+  +|
| ** |
|&lt;**&gt;|
------    -&gt;    5

______
|\^$@|
|987 |
| 456|
|/hi!|
------    -&gt;    14

______
|THIS|
| is |
| a. |
|BOOK|
------    -&gt;    11

______
|////|
|////|
|////|
|////|
------    -&gt;    1

______
|abcd|
|efgh|
|ijkl|
|mnop|
------    -&gt;    16

______
|{. }|
|/. /|
|/. /}
|/. /|
------    -&gt;    3

______
{    |
| .. |
|    }
{    |
--~~--    -&gt;    -4

~~~~~~
{    }
{    }
{    }
{    }
~~~~~~    -&gt;    -20

______
|~~~~|
|.   |
{....}
|.   |
------    -&gt;    0

______
|{~~}|
|    |
|    |
|    |
------    -&gt;    3

__~~__
|{~~}|
|    |
|    |
{    |
-----~    -&gt;    -1
JavaScript (ES6),  75 74  73 bytes
Takes a single string of 36 characters as input, i.e. without any line feed.

s=&gt;s.replace(o=/[^ |_-]/g,(c,n)=&gt;t+=n*9%56%37%9&amp;1?o[c]^(o[c]=1):-1,t=0)|t

Try it online!
How?
We filter out spaces, pipes, underscores and hyphens:
/[^ |_-]/g

It means that we're going to match only:

scratches on the border (-1 point)
or non-space characters on the cover (+1 point the first time each of them appears)

Given the 0-indexed position \$n\$ of the character in the input string, the shortest solution I've found so far to figure out if we're located on the border or on the cover is the following convoluted modulo chain:
$$\big(((9\times n)\bmod 56)\bmod 37\big)\bmod 9$$
which gives:
$$\begin{pmatrix}
0&amp;1&amp;2&amp;3&amp;4&amp;5\\
6&amp;7&amp;8&amp;9&amp;10&amp;11\\
12&amp;13&amp;14&amp;15&amp;16&amp;17\\
18&amp;19&amp;20&amp;21&amp;22&amp;23\\
24&amp;25&amp;26&amp;27&amp;28&amp;29\\
30&amp;31&amp;32&amp;33&amp;34&amp;35
\end{pmatrix}
\rightarrow
\begin{pmatrix}
\color{blue}0&amp;\color{blue}0&amp;\color{blue}0&amp;\color{blue}0&amp;\color{blue}0&amp;\color{blue}8\\
\color{blue}8&amp;7&amp;7&amp;7&amp;7&amp;\color{blue}6\\
\color{blue}6&amp;5&amp;5&amp;5&amp;5&amp;\color{blue}4\\
\color{blue}4&amp;3&amp;3&amp;3&amp;3&amp;\color{blue}2\\
\color{blue}2&amp;1&amp;1&amp;1&amp;1&amp;\color{blue}0\\
\color{blue}0&amp;\color{blue}0&amp;\color{blue}8&amp;\color{blue}8&amp;\color{blue}8&amp;\color{blue}8
\end{pmatrix}$$
With even numbers on the border and odd numbers on the cover.
Generalization of the formula
Given a square matrix of width \$w&gt;3\$ whose cells are indexed from \$0\$ to \$w^2-1\$, the \$n\$-th cell is located on a border iff the result of the following expression is even:
$$\big(((p\times n)\bmod m_0)\bmod m_1\big)\bmod p$$
with:
$$p=2w-3$$
$$m_0=2\cdot (w-1)^2+w$$
$$m_1=2\cdot (w-2)^2+w-1$$
Try it online!
NB: This is an empirical result that I didn't attempt to prove.