Update app.py
Browse files
app.py
CHANGED
|
@@ -14,6 +14,10 @@ st.set_page_config(layout="wide", page_title="K-Space to MRI")
|
|
| 14 |
|
| 15 |
st.markdown("""
|
| 16 |
<style>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
html, body, [class*="st-"] {
|
| 18 |
font-size: 18px;
|
| 19 |
}
|
|
@@ -95,30 +99,34 @@ def get_image_from_plot(fig):
|
|
| 95 |
buf.seek(0)
|
| 96 |
return Image.open(buf)
|
| 97 |
|
| 98 |
-
# แก้ไขสร้างภาพองค์ประกอบแผนผังแกนตามตัวอย่าง (ไม่มีลายคลื่น มีกรอบนอกและรายละเอียดแกนครบ)
|
| 99 |
def draw_kspace_diagram():
|
| 100 |
fig, ax = plt.subplots(figsize=(6, 6))
|
| 101 |
|
| 102 |
-
# วาดกรอบ
|
| 103 |
-
rect = plt.Rectangle((-1, -1), 2, 2, fill=False, edgecolor='black', lw=
|
| 104 |
ax.add_patch(rect)
|
| 105 |
|
| 106 |
-
# วาดลูกศรตัดกันตรงกลาง
|
| 107 |
-
ax.annotate('', xy=(0.
|
| 108 |
-
ax.annotate('', xy=(0, 0.
|
| 109 |
|
| 110 |
-
#
|
| 111 |
-
ax.text(
|
| 112 |
-
ax.text(-
|
| 113 |
-
ax.text(0,
|
| 114 |
-
ax.text(0, -
|
| 115 |
|
| 116 |
-
#
|
| 117 |
-
|
| 118 |
-
ax.
|
|
|
|
| 119 |
|
| 120 |
-
|
| 121 |
-
ax.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
ax.axis('off')
|
| 123 |
|
| 124 |
plt.tight_layout()
|
|
@@ -317,6 +325,8 @@ with col_main:
|
|
| 317 |
|
| 318 |
st.progress((st.session_state.fill_step + 1) / total_anim_steps)
|
| 319 |
|
|
|
|
|
|
|
| 320 |
anim_placeholder = st.empty()
|
| 321 |
with anim_placeholder.container():
|
| 322 |
col_anim1, col_anim2 = st.columns([1, 1])
|
|
@@ -324,6 +334,7 @@ with col_main:
|
|
| 324 |
st.image(draw_pulse_sequence(st.session_state.fill_step, total_anim_steps), use_container_width=True)
|
| 325 |
with col_anim2:
|
| 326 |
st.image(draw_kspace_filling(st.session_state.fill_step, total_anim_steps), use_container_width=True)
|
|
|
|
| 327 |
|
| 328 |
st.markdown("""
|
| 329 |
---
|
|
@@ -347,7 +358,7 @@ with col_main:
|
|
| 347 |
- **มุมของจุด (ทิศทาง):** ตำแหน่งของจุดเมื่อเทียบกับจุดศูนย์กลาง จะเป็นตัวบอกว่าแผ่นลวดลายคลื่นนี้จะ **"เอี���ง"** ไปในทิศทางไหน
|
| 348 |
- **จุดศูนย์กลางเป๊ะ (Origin):** จะเป็นคลื่นที่ไม่มีความถี่ ค่าความถี่ของคลื่นเป็นศูนย์ ดังนั้นตรงกลางจะไม่เห็นลักษณะรูปคลื่น
|
| 349 |
2. **ความสว่างของจุด (Amplitude / Magnitude) บอก "ปริมาณ/น้ำหนัก (Weight)"**
|
| 350 |
-
- ความสว่าง
|
| 351 |
- **จุดสว่างมาก:** ภาพ MRI มีแผ่นลวดลายชนิดนี้เป็นส่วนประกอบอยู่ **เยอะมาก (มีความสำคัญต่อภาพสูง)**
|
| 352 |
- **จุดมืดหรือจาง:** ภาพ MRI แทบจะไม่มีลวดลายชนิดนี้ประกอบอยู่เลย
|
| 353 |
""")
|
|
|
|
| 14 |
|
| 15 |
st.markdown("""
|
| 16 |
<style>
|
| 17 |
+
/* CSS แก้ปัญหาการสั่นของหน้าจอ */
|
| 18 |
+
.stApp { transition: none !important; }
|
| 19 |
+
/* กำหนดความสูงตายตัวให้กับ container กราฟ */
|
| 20 |
+
.fixed-height-chart { min-height: 500px; display: flex; align-items: center; justify-content: center; }
|
| 21 |
html, body, [class*="st-"] {
|
| 22 |
font-size: 18px;
|
| 23 |
}
|
|
|
|
| 99 |
buf.seek(0)
|
| 100 |
return Image.open(buf)
|
| 101 |
|
|
|
|
| 102 |
def draw_kspace_diagram():
|
| 103 |
fig, ax = plt.subplots(figsize=(6, 6))
|
| 104 |
|
| 105 |
+
# วาดกรอบนอก
|
| 106 |
+
rect = plt.Rectangle((-1, -1), 2, 2, fill=False, edgecolor='black', lw=3)
|
| 107 |
ax.add_patch(rect)
|
| 108 |
|
| 109 |
+
# วาดแกนลูกศรตัดกันตรงกลาง
|
| 110 |
+
ax.annotate('', xy=(0.95, 0), xytext=(-0.95, 0), arrowprops=dict(arrowstyle='<|-|>', color='black', lw=2))
|
| 111 |
+
ax.annotate('', xy=(0, 0.95), xytext=(0, -0.95), arrowprops=dict(arrowstyle='<|-|>', color='black', lw=2))
|
| 112 |
|
| 113 |
+
# ตัวอักษรบอกทิศทาง +kx, -kx, +ky, -ky
|
| 114 |
+
ax.text(1.1, 0, '+kx', fontsize=20, fontweight='bold', va='center')
|
| 115 |
+
ax.text(-1.1, 0, '-kx', fontsize=20, fontweight='bold', va='center', ha='right')
|
| 116 |
+
ax.text(0, 1.1, '+ky', fontsize=20, fontweight='bold', ha='center')
|
| 117 |
+
ax.text(0, -1.1, '-ky', fontsize=20, fontweight='bold', ha='center', va='top')
|
| 118 |
|
| 119 |
+
# Label บอกชื่อแกน (เอาไว้ข้างนอกกรอบแบบในรูป)
|
| 120 |
+
# Frequency axis ด้านล่าง
|
| 121 |
+
ax.annotate('', xy=(1, -1.3), xytext=(-1, -1.3), arrowprops=dict(arrowstyle='<|-|>', color='black', lw=4))
|
| 122 |
+
ax.text(0, -1.4, 'kx (Frequency)', ha='center', va='top', fontsize=16, fontweight='bold')
|
| 123 |
|
| 124 |
+
# Phase axis ด้านซ้าย
|
| 125 |
+
ax.annotate('', xy=(-1.3, 1), xytext=(-1.3, -1), arrowprops=dict(arrowstyle='<|-|>', color='black', lw=4))
|
| 126 |
+
ax.text(-1.4, 0, 'ky (Phase)', ha='right', va='center', rotation=90, fontsize=16, fontweight='bold')
|
| 127 |
+
|
| 128 |
+
ax.set_xlim(-1.8, 1.4)
|
| 129 |
+
ax.set_ylim(-1.8, 1.4)
|
| 130 |
ax.axis('off')
|
| 131 |
|
| 132 |
plt.tight_layout()
|
|
|
|
| 325 |
|
| 326 |
st.progress((st.session_state.fill_step + 1) / total_anim_steps)
|
| 327 |
|
| 328 |
+
# ใช้ตีกรอบ Container เพื่อกันการกระโดดสั่นของ Layout
|
| 329 |
+
st.markdown('<div class="fixed-height-chart">', unsafe_allow_html=True)
|
| 330 |
anim_placeholder = st.empty()
|
| 331 |
with anim_placeholder.container():
|
| 332 |
col_anim1, col_anim2 = st.columns([1, 1])
|
|
|
|
| 334 |
st.image(draw_pulse_sequence(st.session_state.fill_step, total_anim_steps), use_container_width=True)
|
| 335 |
with col_anim2:
|
| 336 |
st.image(draw_kspace_filling(st.session_state.fill_step, total_anim_steps), use_container_width=True)
|
| 337 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
| 338 |
|
| 339 |
st.markdown("""
|
| 340 |
---
|
|
|
|
| 358 |
- **มุมของจุด (ทิศทาง):** ตำแหน่งของจุดเมื่อเทียบกับจุดศูนย์กลาง จะเป็นตัวบอกว่าแผ่นลวดลายคลื่นนี้จะ **"เอี���ง"** ไปในทิศทางไหน
|
| 359 |
- **จุดศูนย์กลางเป๊ะ (Origin):** จะเป็นคลื่นที่ไม่มีความถี่ ค่าความถี่ของคลื่นเป็นศูนย์ ดังนั้นตรงกลางจะไม่เห็นลักษณะรูปคลื่น
|
| 360 |
2. **ความสว่างของจุด (Amplitude / Magnitude) บอก "ปริมาณ/น้ำหนัก (Weight)"**
|
| 361 |
+
- ความสว่างของจุดไม่ได้แปลว่าภาพ MRI ตรงนั้นจะสว่าง แต่มันบอกถึง **"ปริมาณ/น้ำหนัก (Weight)"**
|
| 362 |
- **จุดสว่างมาก:** ภาพ MRI มีแผ่นลวดลายชนิดนี้เป็นส่วนประกอบอยู่ **เยอะมาก (มีความสำคัญต่อภาพสูง)**
|
| 363 |
- **จุดมืดหรือจาง:** ภาพ MRI แทบจะไม่มีลวดลายชนิดนี้ประกอบอยู่เลย
|
| 364 |
""")
|