preserve cutoff line color in rotated preview
This commit is contained in:
@@ -86,9 +86,11 @@ type LibraryInfo = {
|
||||
type StoredDeformationJob = {
|
||||
job: BackendJob;
|
||||
progress: number;
|
||||
renderVersion?: string;
|
||||
};
|
||||
|
||||
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'
|
||||
? 'http://127.0.0.1:8787'
|
||||
@@ -109,6 +111,10 @@ function readStoredDeformationJob(): StoredDeformationJob | null {
|
||||
if (!rawValue) return null;
|
||||
const parsed = JSON.parse(rawValue) as StoredDeformationJob;
|
||||
if (!parsed?.job?.id) return null;
|
||||
if (parsed.renderVersion !== DEFORMATION_RESULT_RENDER_VERSION) {
|
||||
window.localStorage.removeItem(DEFORMATION_JOB_STORAGE_KEY);
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
job: parsed.job,
|
||||
progress: Math.max(0, Math.min(100, parsed.progress || 0)),
|
||||
@@ -417,6 +423,7 @@ export default function App() {
|
||||
JSON.stringify({
|
||||
job: deformationJob,
|
||||
progress: deformationJob.status === 'completed' ? 100 : progress,
|
||||
renderVersion: DEFORMATION_RESULT_RENDER_VERSION,
|
||||
})
|
||||
);
|
||||
}, [deformationJob, progress]);
|
||||
|
||||
@@ -159,8 +159,8 @@ def preview_deform_2d(image, angle_degrees):
|
||||
except Exception:
|
||||
return image
|
||||
|
||||
arr = np.asarray(image.convert("L")).astype(np.float32)
|
||||
h, w = arr.shape
|
||||
arr = np.asarray(image.convert("RGB")).astype(np.float32)
|
||||
h, w, _ = arr.shape
|
||||
yy, xx = np.mgrid[0:h, 0:w]
|
||||
|
||||
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_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")
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user