Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions src/vstarstack/library/debayer/bayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,28 @@ class DebayerMethod(Enum):
CFA = 1,
INTERPOLATE = 2,

def generate_mask(name):
def generate_mask(name : str):
"""Generate mask by name"""
used_colors = set(name)
items = name.split("_")
w = int(items[0])
h = int(items[1])

if w != 2 or h != 2:
raise NotImplementedError("Now only 2x2 bayer filters are supported")

colors = items[2]
used_colors = set(colors)
mask = {}
for color in used_colors:
mask[color] = [[0, 0], [0, 0]]
mask[color] = np.zeros((h,w))

pixels = ((0,0),(0,1),(1,0),(1,1))
pixels = []
for y in range(h):
for x in range(w):
pixels.append((y,x))

for i, crd in enumerate(pixels):
mask[name[i]][crd[0]][crd[1]] = 1
mask[colors[i]][crd[0]][crd[1]] = 1

result_mask = {}
for color in used_colors:
Expand Down
33 changes: 26 additions & 7 deletions src/vstarstack/library/loaders/nef.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,50 @@
#

import rawpy
import numpy as np
import exifread
from exifread.classes import IfdTag

import vstarstack.library.common
import vstarstack.library.data

import vstarstack.library.loaders.tags


def readnef(filename: str):
"""Read NEF file"""
img = rawpy.imread(filename)
image = img.raw_image_visible
pattern = img.raw_pattern
color_desc = img.color_desc

pattern = [pattern[0,0], pattern[0,1], pattern[1,0], pattern[1,1]]
bayer = "bayer_2_2_" + "".join([color_desc.decode('ascii')[index] for index in pattern])

tags = vstarstack.library.loaders.tags.read_tags(filename)
with open(filename, 'rb') as file:
tags = exifread.process_file(file)

params = {
"w": image.data.shape[1],
"h": image.data.shape[0],
}

exp = tags["shutter"]*tags["iso"]
if "EXIF ExposureTime" in tags:
tag = tags["EXIF ExposureTime"]
exposure = float(tag.values[0])
else:
exposure = 1

iso = 1

exp = exposure * iso

printable_tags = {}
for tag_name in tags:
printable_tags[tag_name] = tags[tag_name].printable

dataframe = vstarstack.library.data.DataFrame(params, tags)
dataframe = vstarstack.library.data.DataFrame(params, printable_tags)
dataframe.add_channel(image, "raw", encoded=True, brightness=True, signal=True)
dataframe.add_parameter("bayerGBRG", "format")
dataframe.add_parameter(bayer, "format")
dataframe.add_parameter(exp, "weight")
dataframe.add_parameter(exposure, "exposure")
dataframe.add_parameter(iso, "gain")

yield dataframe
34 changes: 26 additions & 8 deletions src/vstarstack/library/loaders/ser.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,62 +101,80 @@ def readser(fname: str):
elif colorid == 8:
shape = (height, width, 1)
channels = ["raw"]
image_format = "bayerRGGB"
image_format = "bayer_2_2_RGGB"
opts["encoded"] = True
opts["brightness"] = True
opts["signal"] = True
vpp = 1
elif colorid == 9:
shape = (height, width, 1)
channels = ["raw"]
image_format = "bayerGRBG"
image_format = "bayer_2_2_GRBG"
opts["encoded"] = True
opts["brightness"] = True
opts["signal"] = True
vpp = 1
elif colorid == 10:
shape = (height, width, 1)
channels = ["raw"]
image_format = "bayerGBRG"
image_format = "bayer_2_2_GBRG"
opts["encoded"] = True
opts["brightness"] = True
opts["signal"] = True
vpp = 1
elif colorid == 11:
shape = (height, width, 1)
channels = ["raw"]
image_format = "bayerBGGR"
image_format = "bayer_2_2_BGGR"
opts["encoded"] = True
opts["brightness"] = True
opts["signal"] = True
vpp = 1
elif colorid == 16:
shape = (height, width, 1)
channels = ["raw"]
image_format = "bayerCYYM"
image_format = "bayer_2_2_CYYM"
opts["encoded"] = True
opts["brightness"] = True
opts["signal"] = True
vpp = 1
elif colorid == 17:
shape = (height, width, 1)
channels = ["raw"]
image_format = "bayerYCMY"
image_format = "bayer_2_2_YCMY"
opts["encoded"] = True
opts["brightness"] = True
opts["signal"] = True
vpp = 1
elif colorid == 18:
shape = (height, width, 1)
channels = ["raw"]
image_format = "bayerYMCY"
image_format = "bayer_2_2_YMCY"
opts["encoded"] = True
opts["brightness"] = True
opts["signal"] = True
vpp = 1
elif colorid == 19:
shape = (height, width, 1)
channels = ["raw"]
image_format = "bayerMYYC"
image_format = "bayer_2_2_MYYC"
opts["encoded"] = True
opts["brightness"] = True
opts["signal"] = True
vpp = 1
elif colorid == 100:
shape = (height, width, 3)
channels = ["R", "G", "B"]
image_format = "flat"
opts["brightness"] = True
opts["signal"] = True
vpp = 3
elif colorid == 101:
shape = (height, width, 3)
channels = ["B", "G", "R"]
image_format = "flat"
opts["brightness"] = True
opts["signal"] = True
vpp = 3
else:
print(f"Unsupported colorid = {colorid}")
Expand Down
1 change: 1 addition & 0 deletions src/vstarstack/library/loaders/tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@ def read_tags(filename):
if name in tags:
res[tag_name] = float(tags[name].values[variant_id])
break


return res
2 changes: 1 addition & 1 deletion src/vstarstack/library/loaders/yuv.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def readyuv(fname: str, width: int, height: int):
exptime = 1

dataframe.add_channel(yuv, "raw", encoded=True, signal=True)
dataframe.add_parameter("yuv422", "format")
dataframe.add_parameter("yuv_422", "format")
dataframe.add_parameter(exptime, "weight")
yield dataframe
frame_id += 1
12 changes: 10 additions & 2 deletions src/vstarstack/tool/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,17 @@ def display(_project: vstarstack.tool.cfg.Project, argv: list):
img1, _ = df1.get_channel(channel)
img2, _ = df2.get_channel(channel)

img1 = img1 / np.amax(img1)
img2 = img2 / np.amax(img2)

img1 = np.clip(img1/np.amax(img1)*slope, 0, 1)
img2 = np.clip(img2/np.amax(img2)*slope, 0, 1)
median1 = np.median(img1)
median2 = np.median(img2)

slope1 = 0.5 / median1
slope2 = 0.5 / median2

img1 = np.clip(img1*slope1, 0, 1)
img2 = np.clip(img2*slope2, 0, 1)

img1 = (img1 * 255).astype(np.uint8)
img2 = (img2 * 255).astype(np.uint8)
Expand Down
2 changes: 1 addition & 1 deletion src/vstarstack/tool/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"camera": {
"pixel_W": (float, 3.0),
"pixel_H": (float, 3.0),
"format": (str, "flat"),
"format": (str, "COPY"),
},
"scope": {
"F": (float, 1000.0),
Expand Down
6 changes: 3 additions & 3 deletions src/vstarstack/tool/decode.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ def _process_file(name, default_format, fname, output):
mode = default_format

print(f"Mode = {mode}")
if mode[:5] == "bayer":
mask_desc = mode[5:9]
if mode[:6] == "bayer_":
mask_desc = mode[6:]
mask = vstarstack.library.debayer.bayer.generate_mask(mask_desc)
method = vstarstack.tool.cfg.get_param("method", str, "SUBSAMPLE")
if method == "SUBSAMPLE":
Expand All @@ -49,7 +49,7 @@ def _process_file(name, default_format, fname, output):
method = DebayerMethod.INTERPOLATE

dataframe = vstarstack.library.debayer.bayer.debayer_dataframe(dataframe, mask, "raw", method)
elif mode == "yuv422":
elif mode == "yuv_422":
dataframe = vstarstack.library.debayer.yuv422.yuv_422_dataframe(dataframe, "raw")
else:
return
Expand Down
1 change: 0 additions & 1 deletion src/vstarstack/tool/readimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ def _work(reader,
img_format = project.config.telescope.camera.format
if img_format != "COPY":
dataframe.add_parameter(img_format, "format")

vstarstack.tool.common.check_dir_exists(outfname)
dataframe.store(outfname)

Expand Down
6 changes: 3 additions & 3 deletions tests/test_debayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def test_1():
layer[0::2,1::2] = 0.1 # G
layer[1::2,0::2] = 0.3 # G
layer[1::2,1::2] = 1.0 # B
mask = vstarstack.library.debayer.bayer.generate_mask("RGGB")
mask = vstarstack.library.debayer.bayer.generate_mask("2_2_RGGB")
df = DataFrame(params = {"weight":1, "w" : 16, "h" : 16})
df.add_channel(layer, "raw", brightness=True, signal=True, normed=False)
result = vstarstack.library.debayer.bayer.debayer_dataframe(df, mask, "raw", DebayerMethod.SUBSAMPLE)
Expand Down Expand Up @@ -64,7 +64,7 @@ def test_2():
layer[0::2,1::2] = 0.1 # G
layer[1::2,0::2] = 0.3 # G
layer[1::2,1::2] = 1.0 # B
mask = vstarstack.library.debayer.bayer.generate_mask("RGGB")
mask = vstarstack.library.debayer.bayer.generate_mask("2_2_RGGB")
df = DataFrame(params = {"weight":1, "w" : 16, "h" : 16})
df.add_channel(layer, "raw", brightness=True, signal=True, normed=False)
result = vstarstack.library.debayer.bayer.debayer_dataframe(df, mask, "raw", DebayerMethod.CFA)
Expand Down Expand Up @@ -125,7 +125,7 @@ def test_3():
layer[0::2,1::2] = 0.1 # G
layer[1::2,0::2] = 0.3 # G
layer[1::2,1::2] = 1.0 # B
mask = vstarstack.library.debayer.bayer.generate_mask("RGGB")
mask = vstarstack.library.debayer.bayer.generate_mask("2_2_RGGB")
df = DataFrame(params = {"weight":1, "w" : 16, "h" : 16})
df.add_channel(layer, "raw", brightness=True, signal=True, normed=False)
result = vstarstack.library.debayer.bayer.debayer_dataframe(df, mask, "raw", DebayerMethod.INTERPOLATE)
Expand Down