2d to 3d house design image conversion
To upload files, please first save the app
import streamlit as st
import numpy as np
from PIL import Image
import io
st.title("2D to 3D House Design Converter")
st.write("""
This app demonstrates a simplified 2D to 3D house design visualization.
Upload a 2D floor plan image, and see a basic 3D representation.
""")
def create_simple_3d_view(image):
# Convert the image to grayscale
gray_image = image.convert('L')
# Get image data as numpy array
img_array = np.array(gray_image)
# Create a simple height map (this is a simplified example)
height_map = (img_array / 255.0) * 50 # Scale height between 0 and 50
# Create 3D visualization using matplotlib
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure(figsize=(10, 8))
ax = fig.add_subplot(111, projection='3d')
x = np.arange(0, img_array.shape[1], 1)
y = np.arange(0, img_array.shape[0], 1)
X, Y = np.meshgrid(x, y)
# Plot the surface
surf = ax.plot_surface(X, Y, height_map, cmap='viridis')
# Add color bar
fig.colorbar(surf)
# Set labels
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Height')
# Save plot to bytes buffer
buf = io.BytesIO()
plt.savefig(buf, format='png')
buf.seek(0)
return buf
# File uploader
uploaded_file = st.file_uploader("Upload a 2D house floor plan", type=['png', 'jpg', 'jpeg'])
if uploaded_file is not None:
# Display original image
image = Image.open(uploaded_file)
st.subheader("Original 2D Floor Plan")
st.image(image, use_column_width=True)
# Create and display 3D view
st.subheader("Simple 3D Visualization")
st.write("(This is a basic height-map based visualization)")
# Generate 3D view
three_d_buf = create_simple_3d_view(image)
three_d_image = Image.open(three_d_buf)
st.image(three_d_image, use_column_width=True)
st.info("""
Note: This is a simplified demonstration that creates a basic 3D visualization
using height mapping. A real 2D to 3D conversion would require more sophisticated
computer vision and 3D modeling techniques.
""")
st.sidebar.title("About")
st.sidebar.write("""
This app provides a basic demonstration of converting 2D floor plans to 3D visualizations.
The conversion is simplified and uses basic height mapping techniques.
To use:
1. Upload a 2D floor plan image
2. View the generated 3D visualization
""")
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?