preserve cutoff line color in rotated preview
This commit is contained in:
@@ -86,9 +86,11 @@ type LibraryInfo = {
|
|||||||
type StoredDeformationJob = {
|
type StoredDeformationJob = {
|
||||||
job: BackendJob;
|
job: BackendJob;
|
||||||
progress: number;
|
progress: number;
|
||||||
|
renderVersion?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
const DEFORMATION_JOB_STORAGE_KEY = 'head_ct_morph_deformation_job';
|
const DEFORMATION_JOB_STORAGE_KEY = 'head_ct_morph_deformation_job';
|
||||||
|
const DEFORMATION_RESULT_RENDER_VERSION = 'quick-preview-cutoff-only-v1';
|
||||||
|
|
||||||
const API_BASE = typeof window === 'undefined'
|
const API_BASE = typeof window === 'undefined'
|
||||||
? 'http://127.0.0.1:8787'
|
? 'http://127.0.0.1:8787'
|
||||||
@@ -109,6 +111,10 @@ function readStoredDeformationJob(): StoredDeformationJob | null {
|
|||||||
if (!rawValue) return null;
|
if (!rawValue) return null;
|
||||||
const parsed = JSON.parse(rawValue) as StoredDeformationJob;
|
const parsed = JSON.parse(rawValue) as StoredDeformationJob;
|
||||||
if (!parsed?.job?.id) return null;
|
if (!parsed?.job?.id) return null;
|
||||||
|
if (parsed.renderVersion !== DEFORMATION_RESULT_RENDER_VERSION) {
|
||||||
|
window.localStorage.removeItem(DEFORMATION_JOB_STORAGE_KEY);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
job: parsed.job,
|
job: parsed.job,
|
||||||
progress: Math.max(0, Math.min(100, parsed.progress || 0)),
|
progress: Math.max(0, Math.min(100, parsed.progress || 0)),
|
||||||
@@ -417,6 +423,7 @@ export default function App() {
|
|||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
job: deformationJob,
|
job: deformationJob,
|
||||||
progress: deformationJob.status === 'completed' ? 100 : progress,
|
progress: deformationJob.status === 'completed' ? 100 : progress,
|
||||||
|
renderVersion: DEFORMATION_RESULT_RENDER_VERSION,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}, [deformationJob, progress]);
|
}, [deformationJob, progress]);
|
||||||
|
|||||||
@@ -159,8 +159,8 @@ def preview_deform_2d(image, angle_degrees):
|
|||||||
except Exception:
|
except Exception:
|
||||||
return image
|
return image
|
||||||
|
|
||||||
arr = np.asarray(image.convert("L")).astype(np.float32)
|
arr = np.asarray(image.convert("RGB")).astype(np.float32)
|
||||||
h, w = arr.shape
|
h, w, _ = arr.shape
|
||||||
yy, xx = np.mgrid[0:h, 0:w]
|
yy, xx = np.mgrid[0:h, 0:w]
|
||||||
|
|
||||||
pivot_x = int(w * 0.55)
|
pivot_x = int(w * 0.55)
|
||||||
@@ -183,7 +183,11 @@ def preview_deform_2d(image, angle_degrees):
|
|||||||
src_x = pivot_x + cos_t * dx + sin_t * dy
|
src_x = pivot_x + cos_t * dx + sin_t * dy
|
||||||
src_y = pivot_y - sin_t * dx + cos_t * dy
|
src_y = pivot_y - sin_t * dx + cos_t * dy
|
||||||
|
|
||||||
warped = map_coordinates(arr, [src_y, src_x], order=1, mode="constant", cval=0)
|
warped_channels = [
|
||||||
|
map_coordinates(arr[..., channel], [src_y, src_x], order=1, mode="constant", cval=0)
|
||||||
|
for channel in range(arr.shape[2])
|
||||||
|
]
|
||||||
|
warped = np.stack(warped_channels, axis=2)
|
||||||
return Image.fromarray(np.clip(warped, 0, 255).astype(np.uint8)).convert("RGB")
|
return Image.fromarray(np.clip(warped, 0, 255).astype(np.uint8)).convert("RGB")
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user