wenjun99 commited on
Commit
f59f5c6
·
verified ·
1 Parent(s): 8cbd019

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -28
app.py CHANGED
@@ -34,22 +34,6 @@ def image_to_binary_labels_rgb(img: Image.Image, max_pixels: int = 256) -> list[
34
  bits.extend(channel_bits)
35
  return bits
36
 
37
- def binary_labels_to_image(binary_labels: list[int], width: int = None, height: int = None) -> Image.Image:
38
- """
39
- Convert binary labels (0/1) into a grayscale image.
40
- """
41
- total_pixels = len(binary_labels)
42
- if width is None or height is None:
43
- side = int(np.ceil(np.sqrt(total_pixels)))
44
- width = height = side
45
- needed_pixels = width * height
46
- if total_pixels < needed_pixels:
47
- binary_labels += [0] * (needed_pixels - total_pixels)
48
- array = np.array(binary_labels, dtype=np.uint8) * 255
49
- image_array = array.reshape((height, width))
50
- img = Image.fromarray(image_array, mode='L')
51
- return img
52
-
53
  def binary_labels_to_rgb_image(binary_labels: list[int], width: int = None, height: int = None) -> Image.Image:
54
  """
55
  Convert binary labels (0/1) into an RGB image.
@@ -138,7 +122,7 @@ with tab2:
138
  img = Image.open(uploaded_file)
139
  st.image(img, caption="Uploaded Image", use_column_width=True)
140
 
141
- max_pixels = st.slider("Max number of pixels to encode", min_value=32, max_value=10240, value=256, step=32)
142
 
143
  binary_labels = image_to_binary_labels_rgb(img, max_pixels=max_pixels)
144
 
@@ -158,6 +142,10 @@ with tab2:
158
  df = pd.DataFrame(table_data, columns=[str(h) for h in mutation_site_headers] + ["Edited Sites"])
159
  st.dataframe(df)
160
 
 
 
 
 
161
  st.download_button(
162
  label="Download Image Binary Labels as CSV",
163
  data=','.join(str(b) for b in binary_labels),
@@ -165,14 +153,4 @@ with tab2:
165
  mime="text/csv"
166
  )
167
 
168
- st.subheader("Reconstruct Image from Binary Labels")
169
- option = st.radio("Choose Reconstruction Mode", ["Grayscale", "True Color (RGB)"])
170
-
171
- if st.button("Reconstruct Image"):
172
- if option == "Grayscale":
173
- reconstructed_img = binary_labels_to_image(binary_labels)
174
- else:
175
- reconstructed_img = binary_labels_to_rgb_image(binary_labels)
176
- st.image(reconstructed_img, caption="Reconstructed Image", use_column_width=True)
177
-
178
- # Future: integrate DNA editor mapping for each mutation site here
 
34
  bits.extend(channel_bits)
35
  return bits
36
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
  def binary_labels_to_rgb_image(binary_labels: list[int], width: int = None, height: int = None) -> Image.Image:
38
  """
39
  Convert binary labels (0/1) into an RGB image.
 
122
  img = Image.open(uploaded_file)
123
  st.image(img, caption="Uploaded Image", use_column_width=True)
124
 
125
+ max_pixels = st.slider("Max number of pixels to encode", min_value=32, max_value=1024, value=256, step=32)
126
 
127
  binary_labels = image_to_binary_labels_rgb(img, max_pixels=max_pixels)
128
 
 
142
  df = pd.DataFrame(table_data, columns=[str(h) for h in mutation_site_headers] + ["Edited Sites"])
143
  st.dataframe(df)
144
 
145
+ st.subheader("Reconstructed RGB Image")
146
+ reconstructed_img = binary_labels_to_rgb_image(binary_labels)
147
+ st.image(reconstructed_img, caption="Reconstructed Image", use_column_width=True)
148
+
149
  st.download_button(
150
  label="Download Image Binary Labels as CSV",
151
  data=','.join(str(b) for b in binary_labels),
 
153
  mime="text/csv"
154
  )
155
 
156
+ # Future: integrate DNA editor mapping for each mutation site here