Useful tool of the week: nconvert

nconvert is not open source. nconvert is however very useful. It is freeware (for noncommercial use). It’s part of XnView.

Here is how to rescale a whole lot of images (extension JPG) at once from the Linux command line:

$ for f in *.JPG; do nconvert -o rescale_$f -resize 640 480 $f ; done

That’s it.

 

The Prime Minister of Australia is either a hypocrite or a fool

If he cannot recognise the need to battle climate change, he’s a fool.

If he does recognise the need to battle climate change, then his response to it is utterly hypocritical.

It’s one or the other.

Successful science writing and editing at Biotext

Click for event brite page

On 13 Nov 2019, we (that is to say Biotext, where I work) will be running our popular course about writing reports, thesis and other documents with technical and scientific content. It will take place in our Bruce offices (that is, in Canberra) from 0930 to 1430.

To register or just have a look, you can go to EventBrite.

Click for event brite page

To get a look at the course outline, click on this thumbnail.

Successful science writing course outline

(Main content repeated in text at end of posting.)

Contact me if it’s of any interest. This is a commercial product, and I would not normally post on such a topic, but we’re a small business and we get our message out how we can.

 

Training.

——————————————————————————————-

Course topics

Common problems – looks at examples of typical science writing from a range of sources.

Where to start – outlines a set of questions to ask when first working on a document.

Writing clearly and succinctly – looks at how to avoid pitfalls of scientific writing such as overuse of jargon, passive voice and weak verbs and nouns.

Improving documents through editing – explains where substantive editing fits in the process of producing a document; and covers the different aspects of this stage, such as overall structure, content and logical flow.

‘Bare bones approach’ – outlines how to use a simple checklist to determine what level of editing a document requires. The checklist is useful in assessing your own work or in giving feedback to others.

Making icons for the HP 200LX

Method 1

The first way is to use the built-in icn200lx.exe and draw them pixel-by-pixel on the HP.

Method 2

Another way, useful for converting existing icons and images, is outlined below. It is not very automatic.

Here we have a putative format: http://fileformats.archiveteam.org/wiki/HP_100LX/200LX_icon

The first 8 bytes seem to be (viewed in bvi)

01 00 01 00 2C 00 20 00

And that leaves 192 bytes, or 192 x 8 = 1536 bits. Now, 44 x 32 = 1408, the number of bits needed for a icon of those dimensions. That would leave a tail of 1536 – 1408 = 128 bits = 16 bytes. Now, we have 44 pixels across and 32 rows.

But the last 16 of each file are NOT the same. This is because each row is padded. The image rows are 44 bits long but that would be 5.5 bytes, so each row is actually 6 bytes long with the last half of the last byte ignored. Since there are 32 rows, that gives 32 x 0.5 = 16 bytes.

Correct.

So a black row is           FFFFFFFFFFF0
So a white row is           000000000000
Chequered row starting 0 is 555555555550
Chequered row starting 1 is AAAAAAAAAAA0

We could invent an icon in in bvi.

We can import an icon into ImageJ. File → Import → Raw

Yep!

Can we change it and save it back?

File → Save As → Raw data

But no, it is now 8-bit colour depth. If I save to pgm and then convert to pbm using convert from ImageMagick, I get a file that, if I put the standard ICN header in place of the pgm header (perhaps using bvi), might do the job…

Yep, that works! OK, so that allows an image to be imported into ImageJ and then converted to an HP LX icon. Because of the padded bytes, can we just take a 32×44 image, convert it and use it? Let’s try!

I’ve got an old version of Cal(vi)n, a small vi clone on the LX. Let us see.

ImageJ, File → New →  (we have to make it 8-bit; make it bigger and type on it then crop to the right size and threshold it.

Save as pgm

$ convert vi.pgm vi.pbm
$ bvi vi.pbm

This image has a working ICN on the right and the pbm on the left. All we do it make the top few bytes match up, and the overall file size the same (delete the pgm header, basically, and add the ICN header).

OK!

The copy the vi.pbm to vi.icn on the CF card and put the card back in the LX and … yep, it works. Not very automatic, but it works.

Method 3

Here is a thing to automatically convert almost any image into an icon — of course, it may be garbage! Many nice images don’t work at 1-bit depth, and it changes the aspect ratio.

# This script requires convert from ImageMagick, plus the netpbm tools.
# It works via some temporary files because I am a simpleton.
#
# darren.goossens@gmail.com
#
# Anyone who finds this useful can use it in any way they like.
#
# Convert the image to pgm for intermediate processing; convert's
# rescale did not work for me.
convert "$1" "$1"temporary.pgm
# Rescale, convert to pbm, and grab the last 192 bytes; you may
# want to add some options to pgmtopbm to darken or lighten the result.
pnmscale -xsize 44 -ysize 32 "$1"temporary.pgm | pgmtopbm | tail -c 192 > "$1".tail
# Create the 8-byte icon header
echo -n -e \\x01\\x00\\x01\\x00\\x2c\\x00\\x20\\x00 > /tmp/ICNHEADER
# Concatenate the ICNHEADER and the 192 bytes of image into an .icn file.
# To get the filename, we cut off the extension (everything after the
# FIRST dot). We don't use basename because we don't know the extension.
# (But does not work with relative paths or paths with dots -- eg ../filename.png.)
cat /tmp/ICNHEADER "$1".tail > $(echo "$1" | cut -f 1 -d '.').icn
# Clean up.
rm "$1"temporary.pgm "$1".tail /tmp/ICNHEADER

Note: One should use pamditherbw instead of pgmtopbm. If doing so, we replace pgmtopbm with pamditherbw | pamtopnm. First step dithers, second converts to pbm. pamtopnm should do the right thing automagically, since it chooses pgm/pbm/etc based on image depth.

Yes, that works.

This compares source images with icons, as imported into ImageJ:

This better represents how the look on the LX screen — small and (re)inverted:

Retroluddite

Alpine: [Refusing to write non-encrypted password file]

To save passwords when using Alpine mail program, one creates ~/.pine-passfile:

$ touch ~/.pine-passfile

But when I tried to save a password I got:

[Refusing to write non-encrypted password file]

So why won’t Alpine write to it?

I took a guess.

I edited the .pine-passfile and hit return once. So instead of being completely empty it had a single empty line in it (ie one non-printing character).

Next time I fired up Alpine it worked — it asked me for the master password and then stored my mail account password. Odd but true. Whether only Enter would work, I dunno.

Now, if you want to avoid using the master password, that is also possible. Not a great idea, I guess, but possible.

 

And off we go

 

 

Extract text from images in a Word file using Tesseract

Got a Word file full of screen grabs. Want to get the text.

(1) Save it as a PDF file.

(2) Do this: https://darrengoossens.wordpress.com/2019/01/07/simple-use-of-tesseract-ocr-on-a-multipage-pdf/

(3) Edit the resulting text file.

Here is the uncorrected text, straight out of Tesseract, from an example file (not the one I actually wanted — I cannot post that):

Here is a Word file full of screen shots in formats from which I cannot
easzily extract the text.

AXAA-2020

29 APRIL=-1MAY 2020

AUSTRALIAN X-RAY ANALYTICAL ASSOCIATION

Data security applies to the data wherever it is,
not just when it is in the repository.

True

False

11 out of 20 adults do
more than 19 hours of
housework a week

e
hehbid

L X ¥ ¥y N
S mrxvt

Here is a screenshot of the Word file:

Screen shot of a Word doc with images in it

A sample Word document

(Yes, I know there are errors in the icon array — that was the point of the image, when I used it for real.)

Et seq

Error bars and column graphs in gnuplot

Largely a note to myself, so I remember how I did it. May not be the best way…!

I want to draw a bar chart with error bars.

Here is some model data:

# Mon mm lo hi 
Jan 11 09 13
Feb 12 10 14
Mar 23 21 25
Apr 34 30 40
May 45 40 50
Jun 56 50 60
Jul 67 60 70
Aug 67 60 70
Sep 78 70 83
Oct 67 60 70
Nov 78 75 88
Dec 67 60 77

Say it’s rainfall, with the last two columns being the error interval. Whatever.

I go to the command line and type:

$ gnuplot simple-bar.gnuplot

And I get this:

Plot with blue columns and arbitrary error bars

My plot

How? Here is the script:

# Lines beginning with # are comments
#
# This file is used by running gnuplot from the command line like this:
# $ gnuplot simple-bar.gnuplot
# where $ is the command prompt (eg C:etc\> if on Windows)
#
# The file plots the data in xy.day according to the instructions given.
#
# The lines below are like global options, including the size and the output format. Use 
# the commented-out line for transparency. Useful terminal types (ie output types)
# include: emf, jpeg, postscript, png, pngcairo, pdfcairo, svg, xterm, x11 and dumb.
# Each has its own subset of options.
#set terminal pngcairo transparent enhanced font "arial,10" fontscale 1.0 size 600, 400 
set terminal pngcairo enhanced font "arial,10" fontscale 1.0 size 600, 400 
# Output file name
set output 'simple-bar.png'
# Type of graph
set style data histogram
# Visual details -- solid fill, 0.5 transparency
set style histogram cluster gap 1
set style fill solid 0.5
set boxwidth 0.9
# No xtics, but we do want labels, and do not mirror tics (ie show at top)
set xtics format "" nomirror
# y tic marks plus grid lines
set grid ytics
# Control the look of the error bars
set style histogram errorbars linewidth 1 
set errorbars linecolor black
set bars front
# Define some custom colours using RGB; can also use standard names ("blue")
red = "#FF0000"; green = "#00FF00"; blue = "#0000FF"; skyblue = "#87CEEB";
# We don't set a title -- but we could by uncommenting this next line
#set title "A Sample Bar Chart"
#The legend ('key') -- single data set does not need one
unset key
# But if we want a legend, uncomment this
# set key on outside center bottom 
# y axis label and range -- no details needed for x axis
set ylabel "Rainfall (mm)"
set yrange [0:100]
# Actually do the plot; use cols 2-4 from the file; linecolor gives the color, 
# linewidth 0 removes the outline of the column
plot "xy.dat" using 2:3:4:xtic(1) title "Rain (mm)" linecolor rgb skyblue linewidth 0
# if we want to output in more formats, we can add more set term lines and more output names
# and replot; but graphs will not be identical since the drivers and file types have
# different limitations and defaults (eg what is a line thickness of '1'?)
set term svg enhanced font "arial,13" fontscale 1.0 size 600, 400 background "white"
set output 'simple-bar.svg'
replot
set term postscript eps level1 color font "Helvetica,12" fontscale 1.0 size 9cm, 6cm
#set term postscript eps level1 enhanced color font "arial,12" fontscale 1.0 size 600, 400 
set output 'simple-bar.eps'
replot

Good luck!

Stop Word opening on startup

I have a laptop. Windows 10. I have a paid-for Office 2010 on it, but Windows insists on opening Office 365 (or whatever it is) on startup and asking me to log in to my Microsoft account and register the product.

Task manager → Startup does not show it.

Startup folder in the start menu is empty.

Ran msconfig and in Services disabled Microsoft Office Click-to-run service and Microsoft Account Sign-in Assistant

Restart

Yep, that seemed to work..

Successful science writing and editing at Biotext

On 13 Nov 2019, we (that is to say Biotext, where I work) will be running our popular course about writing reports, thesis and other documents with technical and scientific content. It will take place in our Bruce offices (that is, in Canberra) from 0930 to 1430.

To register or just have a look, you can go to EventBrite.

Click for event brite page

To get a look at the course outline, click on this thumbnail.

Successful science writing course outline

(Main content repeated in text at end of posting.)

Contact me if it’s of any interest. This is a commercial product, and I would not normally post on such a topic, but we’re a small business and we get our message out how we can.

 

Training.

——————————————————————————————-

Course topics

Common problems – looks at examples of typical science writing from a range of sources.

Where to start – outlines a set of questions to ask when first working on a document.

Writing clearly and succinctly – looks at how to avoid pitfalls of scientific writing such as overuse of jargon, passive voice and weak verbs and nouns.

Improving documents through editing – explains where substantive editing fits in the process of producing a document; and covers the different aspects of this stage, such as overall structure, content and logical flow.

‘Bare bones approach’ – outlines how to use a simple checklist to determine what level of editing a document requires. The checklist is useful in assessing your own work or in giving feedback to others.

My ORCID QR code

Never used one myself, but here it is! ORCID is what it says here.

QR code for my ORCID account

Whatever.

QR code for my ORCID account

Whatever, thumbnail size.

 

 

Me there