Pinephone Pro camera: smooth out the triangle dots.

Zooming in and looking at the triangle dot pattern, it is very regular. Changed the image type to png, which is non lossy, and see there are pairs of dots, in the regular pattern, on the green layer.

used GIMP to locate them

here we see the first pixel at 26,29.
the set of four are (in the box):
26,29
25,32
34,45
33,48

these then repeat, at 16 pixel intervals (both horizontal and vertical)

now check to see if is in the raw data file.

using numpy from python, can read the raw file, and using a jupyter notebook, as well as matplotlib and PIL, can display in the notebook the raw data (code pasted here, image of notebook below)

from PIL import Image
import numpy as np
from matplotlib import pyplot as plt
raw = np.fromfile('/home/mobian/Pictures/frame.raw', np.uint8)
# size
w=4208
h=3120
# read single dimensional raw image data array into square array
# starting at px, py, size square x square
px=0
py=0
square=60
plotarray=np.eye(square) # initialize square array
for y in range(0,square):
    for x in range(0,square):
        value = raw[w*(x + px) + (y + py)]
        plotarray[x][y] = int(value)
        
im = Image.fromarray(np.uint8(plotarray))
plt.imshow(im)
plt.rcParams['figure.figsize'] = (6,6)
plt.show()

and it also has the pairs of dots (screen shot of notebook below, with my specific frame.raw file)

now using the measurements, lets calculate the locations of all the dots, the 4 set of co-ordinates, repeated at 16 pixel (x) and 32 pixel (y) intervals

g=16 #gap
for x in range(0,w-4*g,g):
    for y in range(0,h-4*g,g*2):
        raw[26+x+(29+y)*w]= 255
        raw[25+x+(32+y)*w]= 255
        raw[34+x+(45+y)*w]= 255
        raw[33+x+(48+y)*w]= 255

and make them light. Rerun the same plot (slightly bigger and larger, but the same display code from above:

so now how to “remove” them?
simple test: replace with average of 4 “nearest” neighbours. Now due to how the colours are arranged, is not actually the pixel directly next to it, but 2 away (pasted code, but wraps, below screenshot)

g=16
for x in range(0,w-g*4,g):
    for y in range(0,h-g*4,g*2):
        #      y     x                  y-2                       y+2                             x-2                       x+2
        raw[w*(29+y)+26+x]= ( int(raw[w*(27+y)+26+x]) + int(raw[w*(31+y)+26+x]) + int(raw[w*(29+y)+24+x]) + int(raw[w*(29+y)+28+x]) ) /4
        raw[w*(32+y)+25+x]= ( int(raw[w*(30+y)+25+x]) + int(raw[w*(34+y)+25+x]) + int(raw[w*(32+y)+23+x]) + int(raw[w*(32+y)+27+x]) ) /4
        raw[w*(45+y)+34+x]= ( int(raw[w*(43+y)+34+x]) + int(raw[w*(47+y)+34+x]) + int(raw[w*(45+y)+32+x]) + int(raw[w*(45+y)+36+x]) ) /4
        raw[w*(48+y)+33+x]= ( int(raw[w*(46+y)+33+x]) + int(raw[w*(50+y)+33+x]) + int(raw[w*(48+y)+31+x]) + int(raw[w*(48+y)+35+x]) ) /4
raw.tofile('/home/mobian/Pictures/numpy.raw')  

result:

looks smooth!

the last line writes out to a new numpy.raw file.

which we then process with the same ffmpeg commands from the previous post:

original unprocessed / colour balanced + numpy fix

WordPress will let you zoom in to the full size images, if you want to look at the dots.

Still do not know where the dots come from, if someone with better imx258 docs, can send me a link?

I assume I need to set the sensor with different commands…

and still need to fix the focus

Could add these numpy and imagemagick commands to megapixels post processing…

p.s. all of the above (except GIMP) was run on the pinephone pro, including the jupyter notebook.

This entry was posted in tech. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s