mirror of
https://github.com/leaders-of-digital-9-task/backend.git
synced 2024-11-22 01:16:33 +03:00
add point cloud and patology generation
This commit is contained in:
parent
50c52dcdf5
commit
312d145e3b
|
@ -1,3 +1,4 @@
|
||||||
|
from functools import lru_cache
|
||||||
import glob
|
import glob
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
|
@ -9,10 +10,14 @@ from dicom.models import Coordinate, Dicom, Project
|
||||||
from django.core.files import File
|
from django.core.files import File
|
||||||
from django.core.files.uploadedfile import InMemoryUploadedFile, TemporaryUploadedFile
|
from django.core.files.uploadedfile import InMemoryUploadedFile, TemporaryUploadedFile
|
||||||
from utils.generators import generate_charset
|
from utils.generators import generate_charset
|
||||||
|
from typing import List, Union
|
||||||
|
from django.conf import settings
|
||||||
|
import pydicom
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def process_files(
|
def process_files(
|
||||||
files: list[TemporaryUploadedFile | InMemoryUploadedFile], user, slug=None
|
files: List[Union[TemporaryUploadedFile, InMemoryUploadedFile]], user, slug=None
|
||||||
):
|
):
|
||||||
if slug:
|
if slug:
|
||||||
project = Project.objects.get(slug=slug)
|
project = Project.objects.get(slug=slug)
|
||||||
|
@ -23,7 +28,7 @@ def process_files(
|
||||||
if content_type == "DICOM medical imaging data":
|
if content_type == "DICOM medical imaging data":
|
||||||
Dicom.objects.create(file=file, project=project, user=user)
|
Dicom.objects.create(file=file, project=project, user=user)
|
||||||
elif "Zip" in content_type:
|
elif "Zip" in content_type:
|
||||||
dit_path = f"/tmp/{generate_charset(10)}"
|
dit_path = f"tmp/{generate_charset(10)}"
|
||||||
os.mkdir(dit_path)
|
os.mkdir(dit_path)
|
||||||
with zipfile.ZipFile(file.temporary_file_path(), "r") as zip_ref:
|
with zipfile.ZipFile(file.temporary_file_path(), "r") as zip_ref:
|
||||||
zip_ref.extractall(dit_path)
|
zip_ref.extractall(dit_path)
|
||||||
|
@ -51,3 +56,39 @@ def create_coordinate(coordinates, obj):
|
||||||
y=coordinate["y"],
|
y=coordinate["y"],
|
||||||
shape=obj,
|
shape=obj,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def get_bbox(project_id, points, image_range):
|
||||||
|
project: Project = Project.objects.get(slug=project_id)
|
||||||
|
#print(Dicom.objects.all())
|
||||||
|
files = project.files.all()
|
||||||
|
bbox_data = []
|
||||||
|
for file_number in range(image_range[0], image_range[1]+1):
|
||||||
|
print(points[0]['x'])
|
||||||
|
bbox_data.append(
|
||||||
|
pydicom.dcmread(
|
||||||
|
files[file_number].file.path).pixel_array[int(points[0]['x']):int(points[1]['x']), int(points[0]['y']):int(points[1]['y'])].tolist())
|
||||||
|
print(pydicom.dcmread(files[file_number].file.path).pixel_array)
|
||||||
|
print(bbox_data)
|
||||||
|
#print(project.files.all(), "files", project)
|
||||||
|
return []
|
||||||
|
|
||||||
|
@lru_cache(512)
|
||||||
|
def generate_3d_point_cloud(project_slug: str):
|
||||||
|
project = Project.objects.get(slug=project_slug)
|
||||||
|
|
||||||
|
point_clouds = []
|
||||||
|
|
||||||
|
for fileindex, file in enumerate(project.files.all()[::3]):
|
||||||
|
print(fileindex)
|
||||||
|
pixel_array = pydicom.dcmread(
|
||||||
|
file.file.path
|
||||||
|
).pixel_array
|
||||||
|
for iindex, i in enumerate(pixel_array[::3]):
|
||||||
|
for jindex, j in enumerate(i[::3]):
|
||||||
|
if j <= 240:
|
||||||
|
pass
|
||||||
|
#point_clouds.append({'x': jindex, 'y': iindex, 'z': fileindex, 'value': 0})
|
||||||
|
else:
|
||||||
|
point_clouds.append([jindex, iindex, fileindex, j])
|
||||||
|
return point_clouds
|
||||||
|
|
Loading…
Reference in New Issue
Block a user