Converting raw images without headers - image-processing

I have very large (20000x20000+) raw image files where each pixel is represented by 3 bytes. I know the resolution of each image.
Example (for a 4x4 image):
+----------------+----------------+----------------+----------------+
| | | | |
| R G B | R G B | R G B | R G B |
| 0x00 0x01 0x02 | 0x03 0x04 0x05 | 0x06 0x07 0x08 | 0x09 0x0A 0x0B |
| | | | |
+----------------+----------------+----------------+----------------+
| | | | |
| R G B | R G B | R G B | R G B |
| 0x0C 0x0D 0x0E | 0x0F 0x10 0x11 | 0x12 0x13 0x14 | 0x15 0x16 0x17 |
| | | | |
+----------------+----------------+----------------+----------------+
| | | | |
| R G B | R G B | R G B | R G B |
| 0x18 0x19 0x1A | 0x1B 0x1C 0x1D | 0x1E 0x1F 0x20 | 0x21 0x22 0x23 |
| | | | |
+----------------+----------------+----------------+----------------+
| | | | |
| R G B | R G B | R G B | R G B |
| 0x24 0x25 0x26 | 0x27 0x28 0x29 | 0x2A 0x2B 0x2C | 0x2D 0x2E 0x2F |
| | | | |
+----------------+----------------+----------------+----------------+
How do I convert them to BMP images?

Easy. Use ImageMagick in Terminal (or "Command Prompt" thing on Windows). If your file is 1920 px wide by 1080 px tall:
magick -size 1920x1080 -depth 8 RGB:YOURFILE output.bmp
Not sure why anyone would willingly choose to use BMP format though. I would prefer PNG:
magick -size 1920x1080 -depth 8 RGB:YOURFILE output.png
Use convert in place of magick if using v6 ImageMagick.
Or, even easier (since it requires no software installation), make a header and convert them to NetPBM files which Photoshop, GIMP, feh can all read:
{ printf "P6\n%d %d\n255\n" WIDTH HEIGHT ; cat YOURFILE; } > result.ppm

Related

Transpose Two Tables without Blank Values in Google Sheets

I have two Tables in Google Sheet where i want to bring the values to one row with the corresponding quantity in second column from the Second Table.
First Table
+----------------------------+----------------------------+----------------------------+-----------------------------+----------------------------+---+---+----------------------------+
| A | B | C | D | E | F | G | H |
+----------------------------+----------------------------+----------------------------+-----------------------------+----------------------------+---+---+----------------------------+
| . | . | Paralite 1215 Ladies-BKB/4 | Paralite 1215 Ladies-BKB/5 | Paralite 1215 Ladies-BKB/6 | . | . | . |
| Paralite 1216 Ladies-BKR/1 | Paralite 1216 Ladies-BKR/2 | . | . | . | . | . | . |
| . | . | . | . | . | . | . | Paralite 1217 Ladies-BKR/9 |
+----------------------------+----------------------------+----------------------------+-----------------------------+----------------------------+---+---+----------------------------+
Second Table
+---+---+---+---+---+---+---+---+
| A | B | C | D | E | F | G | H |
+---+---+---+---+---+---+---+---+
| 0 | 0 | 8 | 6 | 8 | 0 | 0 | 0 |
| 4 | 8 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 6 |
+---+---+---+---+---+---+---+---+
Output I want
+----------------------------+---+
| A | B |
+----------------------------+---+
| Paralite 1215 Ladies-BKB/4 | 8 |
| Paralite 1215 Ladies-BKB/5 | 6 |
| Paralite 1215 Ladies-BKB/6 | 8 |
| Paralite 1216 Ladies-BKR/1 | 4 |
| Paralite 1216 Ladies-BKR/2 | 8 |
| Paralite 1217 Ladies-BKR/9 | 6 |
+----------------------------+---+
Google Sheet Link :
https://docs.google.com/spreadsheets/d/1c_vaT7-_cTLvPlcquK8Ax4aM6yYUQxBx15WS6yIAwa0/edit?usp=sharing
Try this:
=query(
{
flatten(A2:R7),
flatten(T2:AK7)
},
"where Col1 is not null",
0
)
If that does not cut it for you, please follow MattKing's advice and show your expected results in the sample spreadsheet. Clearly identify in the spreadsheet where the two source tables are and where your expected results are shown.
Use the following query for 2 tables like A1:H3 and A8:H10
=QUERY({FLATTEN(A1:H3),FLATTEN(A8:H10)},
" where Col1 <>'' and Col2 <>0 ",0)A1

IMDBpy - Director name is coming with the characters all divided

I'm trying to get some details about movies from IMDB.
For that I'm using IMDBpy with following code:
import imdb
ia = imdb.IMDb()
top250 = ia.get_top250_movies()
i = 0;
for topmovie in top250:
# First, retrieve the movie object using its ID
movie = ia.get_movie(topmovie.movieID)
cast = movie.get('cast')
topActors = 3
i = i+1;
actor_names = [actor['name'] for actor in cast[:topActors]]
#director_name = [director['director'] for director in cast[:topActors]]
if i <= 10:
print(movie, ';', ' | '.join(movie['genres']),
';', ' | '.join(actor_names),
';', ' | '.join(str(movie['director']))
);
else:
break;
However when I run my code I am getting my results with this format:
The Shawshank Redemption ; Drama ; Tim Robbins | Morgan Freeman | Bob Gunton ; [ | < | P | e | r | s | o | n | | i | d | : | 0 | 0 | 0 | 1 | 1 | 0 | 4 | [ | h | t | t | p | ] | | n | a | m | e | : | _ | D | a | r | a | b | o | n | t | , | | F | r | a | n | k | _ | > | ]
The Godfather ; Crime | Drama ; Marlon Brando | Al Pacino | James Caan ; [ | < | P | e | r | s | o | n | | i | d | : | 0 | 0 | 0 | 0 | 3 | 3 | 8 | [ | h | t | t | p | ] | | n | a | m | e | : | _ | C | o | p | p | o | l | a | , | | F | r | a | n | c | i | s | | F | o | r | d | _ | > | ]
The Godfather: Part II ; Crime | Drama ; Al Pacino | Robert Duvall | Diane Keaton ; [ | < | P | e | r | s | o | n | | i | d | : | 0 | 0 | 0 | 0 | 3 | 3 | 8 | [ | h | t | t | p | ] | | n | a | m | e | : | _ | C | o | p | p | o | l | a | , | | F | r | a | n | c | i | s | | F | o | r | d | _ | > | ]
The Dark Knight ; Action | Crime | Drama | Thriller ; Christian Bale | Heath Ledger | Aaron Eckhart ; [ | < | P | e | r | s | o | n | | i | d | : | 0 | 6 | 3 | 4 | 2 | 4 | 0 | [ | h | t | t | p | ] | | n | a | m | e | : | _ | N | o | l | a | n | , | | C | h | r | i | s | t | o | p | h | e | r | _ | > | ]
12 Angry Men ; Crime | Drama ; Martin Balsam | John Fiedler | Lee J. Cobb ; [ | < | P | e | r | s | o | n | | i | d | : | 0 | 0 | 0 | 1 | 4 | 8 | 6 | [ | h | t | t | p | ] | | n | a | m | e | : | _ | L | u | m | e | t | , | | S | i | d | n | e | y | _ | > | ]
Schindler's List ; Biography | Drama | History ; Liam Neeson | Ben Kingsley | Ralph Fiennes ; [ | < | P | e | r | s | o | n | | i | d | : | 0 | 0 | 0 | 0 | 2 | 2 | 9 | [ | h | t | t | p | ] | | n | a | m | e | : | _ | S | p | i | e | l | b | e | r | g | , | | S | t | e | v | e | n | _ | > | ]
The Lord of the Rings: The Return of the King ; Action | Adventure | Drama | Fantasy ; Noel Appleby | Ali Astin | Sean Astin ; [ | < | P | e | r | s | o | n | | i | d | : | 0 | 0 | 0 | 1 | 3 | 9 | 2 | [ | h | t | t | p | ] | | n | a | m | e | : | _ | J | a | c | k | s | o | n | , | | P | e | t | e | r | _ | > | ]
Pulp Fiction ; Crime | Drama ; Tim Roth | Amanda Plummer | Laura Lovelace ; [ | < | P | e | r | s | o | n | | i | d | : | 0 | 0 | 0 | 0 | 2 | 3 | 3 | [ | h | t | t | p | ] | | n | a | m | e | : | _ | T | a | r | a | n | t | i | n | o | , | | Q | u | e | n | t | i | n | _ | > | ]
The Good, the Bad and the Ugly ; Western ; Eli Wallach | Clint Eastwood | Lee Van Cleef ; [ | < | P | e | r | s | o | n | | i | d | : | 0 | 0 | 0 | 1 | 4 | 6 | 6 | [ | h | t | t | p | ] | | n | a | m | e | : | _ | L | e | o | n | e | , | | S | e | r | g | i | o | _ | > | ]
Fight Club ; Drama ; Edward Norton | Brad Pitt | Meat Loaf ; [ | < | P | e | r | s | o | n | | i | d | : | 0 | 0 | 0 | 0 | 3 | 9 | 9 | [ | h | t | t | p | ] | | n | a | m | e | : | _ | F | i | n | c | h | e | r | , | | D | a | v | i | d | _ | > | ]
As you can see the columns for Director is returning with multipli characters...
How can I solve this?
Already solve this issue:
import imdb
ia = imdb.IMDb()
top250 = ia.get_top250_movies()
i = 0;
for topmovie in top250:
# First, retrieve the movie object using its ID
movie = ia.get_movie(topmovie.movieID)
cast = movie.get('cast')
directors = movie.get('director')
topActors = 3
i = i+1;
actor_names = [actor['name'] for actor in cast[:topActors]]
director_names = [director['name'] for director in directors[:1]]
if i <= 10:
print(movie, ' ; ', ' | '.join(movie['genres']),
' ; ', ' | '.join(actor_names),
' ; ', ' | '.join(director_names)
);
else:
break;
Thanks!
movie['director'] is a list of Movie objects; casting it to str you will get something like "[<Object1>, <Object2>]" and then you use this string as an iterable for the join method.
You should get the directors' names exactly like you do with the cast names.
For example:
print(movie, ';', ' | '.join(movie['genres']),
';', ' | '.join(actor_names),
';', ' | '.join([d['name'] for d in movie['director']])
);

PSQL code missing

My problem on getting one row shown with two null values.
FROM tuotemerkki;
tmtunnus | tmnimi | maa
----------+----------+-------------
1 | McCee | Yhdysvallat
2 | KooTek | Italia
3 | Giardino | Italia
(3 rows)
FROM tuote;
ttunnus | tnimi | kuvaus | suositushinta | tmtunnus
---------+-----------------------+--------------------+---------------+----------
111 | Trimmeri TRCee | tehokas 4-tahtinen | 179.00 | 1
112 | Trimmerisiima Cee | laadukas siima | 6.99 | 1
113 | Moottorisaha MSCee RR | robusti ja raskas | 559.00 | 1
114 | Trimmerisiima Y | yleissiima | 3.99 | 2
115 | Lapio L | kevyt yleislapio | 23.95 | 2
(5 rows)
I need to get this selected with the NULL VALUE on giardino from tmnimi.
tmnimi | tnimi | kuvaus
----------+-----------------------+--------------------
McCee | Trimmeri TRCee | tehokas 4-tahtinen
McCee | Trimmerisiima Cee | laadukas siima
McCee | Moottorisaha MSCee RR | robusti ja raskas
KooTek | Trimmerisiima Y | yleissiima
KooTek | Lapio L | kevyt yleislapio
Giardino | |
(6 rows)
I get only this selected
SELECT tmnimi, tnimi, kuvaus
FROM tuote
CROSS JOIN tuotemerkki
WHERE tuote.tmtunnus = tuotemerkki.tmtunnus;
tmnimi | tnimi | kuvaus
--------+-----------------------+--------------------
McCee | Trimmeri TRCee | tehokas 4-tahtinen
McCee | Trimmerisiima Cee | laadukas siima
McCee | Moottorisaha MSCee RR | robusti ja raskas
KooTek | Trimmerisiima Y | yleissiima
KooTek | Lapio L | kevyt yleislapio
(5 rows)
Use a left join between the two tables:
SELECT
t1.tmnimi,
t2.tnimi,
t2.kuvaus
FROM tuotemerkki t1
LEFT JOIN tuote t2
ON t1.tmtunnus = t2.tmtunnus
When you left join from tuotemerkki to tuote, then every record in the former table is guaranteed to appear in the result set. Since the Giardino record does not match to anything in the tuote table, all the columns from that table would have a NULL value for the Giardino record.

Transpose or Pivot - neo4j collect()

how to transpose a n x m collection in the return statement ? OR before return statement based on a particular column?
example:
A | B | C
aa | 2 | 3
bb | 4 | 6
cc | 5 | 8
dd | 55| 9
To
aa | bb | cc | dd
2 | 4 | 5 | 55
3 | 6 | 8 | 9
Example:
with [{Label:'User',Lang:'English'},{Label:'Usuario',Lang:'Español'},{Label:'用户',Lang:'中文_简体'}] as t unwind t as p return
this returns
p.Label | p.Lang
User | English
Usuario | Español
用户 | 中文_简体
should be transposed to
User | Usuario | 用户
English | Español | 中文_简体
Well, MAYBE there is what you want in APOC.
CALL apoc.help(KEYWORD)
If not, you are good to write your own function
https://neo4j-contrib.github.io/neo4j-apoc-procedures/#_user_defined_functions
Would extract help? This might get you part-way there:
neo4j> with [{Label:'User',Lang:'English'},{Label:'Usuario',Lang:'Español'},{Label:'用户',Lang:'中文_简体'}] as t return extract( i in t | i.Label), extract(i in t | i.Lang);
+--------------------------------------------------------------+
| extract( i in t | i.Label) | extract(i in t | i.Lang) |
+--------------------------------------------------------------+
| ["User", "Usuario", "用户"] | ["English", "Español", "中文_简体"] |
+--------------------------------------------------------------+

URL BNF search part does not make sense

While implementing a Java regular expression for URL based on the URL BNF published by W3C, I've failed to understand the search part. As quoted:
httpaddress h t t p : / / hostport [ / path ] [ ?
search ]
search xalphas [ + search ]
xalphas xalpha [ xalphas ]
xalpha alpha | digit | safe | extra | escape
alpha a | b | c | d | e | f | g | h | i | j | k |
l | m | n | o | p | q | r | s | t | u | v |
w | x | y | z | A | B | C | D | E | F | G |
H | I | J | K | L | M | N | O | P | Q | R |
digit 0 |1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
safe $ | - | _ | # | . | & | + | -
extra ! | * | " | ' | ( | ) | ,
Search claims it is xalphas seperated by a plus sign.
xalphas can contain plus signs by it self, as claimed by safe.
Thus according to my understanding , it should be:
search xalphas
Where am I wrong here?
That's pretty clearly a mistake (+ is a reserved delimiter for URIs), but the BNF you're linking to seems to be out of date. Probably best to use the one included at the end of the latest RFC 3986.

Resources