2d floor plan to 3d converter
Drop files here
or click to upload
import streamlit as st
import numpy as np
from PIL import Image
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import io
st.title("2D Floor Plan to 3D Visualization")
st.write("Upload a 2D floor plan image to generate a basic 3D visualization.")
# File uploader for the floor plan
uploaded_file = st.file_uploader("Choose a floor plan image file", type=['png', 'jpg', 'jpeg'])
if uploaded_file is not None:
# Read and process the image
image = Image.open(uploaded_file)
# Convert to grayscale
gray_image = image.convert('L')
# Convert to numpy array and normalize
floor_plan = np.array(gray_image)
normalized = floor_plan / 255.0
# Create height map (simple elevation based on pixel intensity)
height_map = normalized * 3.0 # Scale factor for height
# Create coordinate grids
x, y = np.meshgrid(np.arange(floor_plan.shape[1]), np.arange(floor_plan.shape[0]))
# Create 3D plot
fig = plt.figure(figsize=(10, 8))
ax = fig.add_subplot(111, projection='3d')
# Plot surface
surf = ax.plot_surface(x, y, height_map, cmap='viridis', alpha=0.8)
# Customize the plot
ax.set_title('3D Visualization')
ax.set_xlabel('Width')
ax.set_ylabel('Length')
ax.set_zlabel('Height')
# Add a color bar
plt.colorbar(surf)
# Display original and 3D visualization
col1, col2 = st.columns(2)
with col1:
st.subheader("Original Floor Plan")
st.image(image, use_column_width=True)
with col2:
st.subheader("3D Visualization")
st.pyplot(fig)
st.write("""
### How it works:
1. The uploaded floor plan is converted to grayscale
2. Pixel intensities are used to create a height map
3. The height map is transformed into a 3D surface plot
Note: This is a simple visualization where darker areas appear lower and lighter areas appear higher.
For more accurate results, you would need a properly annotated floor plan with wall heights and other structural information.
""")
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?