Skip to content

Commit

Permalink
main change is to view masks again using instance channel
Browse files Browse the repository at this point in the history
  • Loading branch information
christinab12 committed Jul 17, 2024
1 parent f3a986b commit 9f66d7d
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 105 deletions.
146 changes: 50 additions & 96 deletions src/client/dcp_client/gui/_filesystem_wig.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import os

import numpy as np
from skimage.color import label2rgb
from skimage.io import imread
from skimage.transform import resize
from skimage.color import label2rgb

from PyQt5.QtWidgets import QFileSystemModel, QStyledItemDelegate
from PyQt5.QtCore import Qt, QRect, QVariant, QDir
from PyQt5.QtGui import QPixmap, QPainter, QImage, QBrush, QPen, QFont
from PyQt5.QtWidgets import QFileSystemModel
from PyQt5.QtCore import Qt, QVariant, QDir
from PyQt5.QtGui import QImage

from dcp_client.utils import settings

class MyQFileSystemModel(QFileSystemModel):
def __init__(self, app):
Expand All @@ -16,6 +15,8 @@ def __init__(self, app):
"""
super().__init__()
self.app = app
self.img_x = 100
self.img_y = 100

def setFilter(self, filters):
"""
Expand Down Expand Up @@ -51,6 +52,7 @@ def headerData(self, section, orientation, role):
else:
return super().headerData(section, orientation, role)


def data(self, index, role=Qt.DisplayRole):
"""
Reimplemented method to provide custom data for the model's items.
Expand All @@ -61,96 +63,48 @@ def data(self, index, role=Qt.DisplayRole):
"""
if not index.isValid():
return QVariant()

if "_seg" in self.filePath(index):
return QVariant()

if role == Qt.DisplayRole:
filepath_img = self.filePath(index)


if role == Qt.DecorationRole:
filepath_img = self.filePath(index)

if filepath_img.endswith(".tiff") or filepath_img.endswith(".png"):
if "_seg" not in filepath_img:
painter = QPainter()

img_x, img_y = 64, 64

filepath_mask = f"{filepath_img.split('.')[0]}_seg.tiff"
img = QImage(filepath_img).scaled(img_x, img_y)

if os.path.exists(filepath_mask):

mask = imread(filepath_mask)[0]
num_objects = len(
self.app.fs_image_storage.search_segs(
os.path.dirname(filepath_img), filepath_img
)
)

mask = resize(
mask,
(int(round(1.5 * img_x)), int(round(1.5 * img_y))),
order=0,
)

mask = label2rgb(mask)
mask = (255 * np.transpose(mask, (1, 0, 2)).copy()).astype(
np.uint8
)

mask = QImage(
mask, mask.shape[1], mask.shape[0], QImage.Format_RGB888
).scaled(
123, 123, Qt.IgnoreAspectRatio, Qt.SmoothTransformation
)

img = img.scaled(
82, 82, Qt.IgnoreAspectRatio, Qt.SmoothTransformation
)
img_x, img_y = 82, 82
painter.begin(mask)

rect_image = QRect(0, img_x // 2, img_x, img_y)

rect_corner_left = QRect(0, 0, img_x // 2, img_y // 2)
rect_corner_bottom = QRect(img_x, img_y, img_x // 2, img_y // 2)

painter.fillRect(
rect_corner_left, QBrush(Qt.white, Qt.SolidPattern)
)
painter.fillRect(
rect_corner_bottom, QBrush(Qt.white, Qt.SolidPattern)
)

painter.drawImage(rect_image, img)

pen = QPen(Qt.black)
painter.setPen(pen)

font = QFont()
font.setFamily("Arial")

font.setPointSize(6)
painter.setFont(font)

painter.drawText(
int(round((5 / 4) * img_x)) - 19,
int(round((5 / 4) * img_x)),
f"{str(num_objects)} masks",
)

painter.end()

pixmap = QPixmap.fromImage(mask)

return pixmap

else:
return img

filepath_img = self.filePath(index)
# if an image of our dataset
if filepath_img.endswith(settings.accepted_types):

# if a mask make sure it is displayed properly
if "_seg" in filepath_img:
img = imread(filepath_img)
if img.ndim > 2: img = img[0]
img = label2rgb(img)
img = (255 * img.copy()).astype(
np.uint8
)#np.transpose(img, (1, 0, 2))
height, width = img.shape[0], img.shape[1]
img = QImage(img,
width,
height,
3 * width,
QImage.Format_RGB888
)
#img = img.scaled(self.img_x, (width*self.img_x)//height, Qt.KeepAspectRatio)
img = img.scaled(self.img_x, self.img_y, Qt.KeepAspectRatio) # yields the same
else:
return None
img = QImage(filepath_img).scaled(self.img_x, self.img_y, Qt.KeepAspectRatio)
'''
# It would be cool if instead of the mask and the image we could show them both merged
# together with label2rgb if the mask exists - would need to remove _seg files from list
filepath_mask = '.'.join(filepath_img.split('.')[:-1])+'_seg.tiff'
if os.path.exists(filepath_mask):
mask = imread(filepath_mask)
if mask.ndim>2: mask = mask[0]
img = imread(filepath_img, as_gray=True)
img = label2rgb(mask, img)
img = QImage(img,
img.shape[1],
img.shape[0],
QImage.Format_RGB888
).scaled(self.img_x, self.img_y, Qt.KeepAspectRatio)
'''
return img

return super().data(index, role)

return super().data(index, role)
10 changes: 9 additions & 1 deletion src/client/dcp_client/gui/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from dcp_client.gui._my_widget import MyWidget
from dcp_client.gui._filesystem_wig import MyQFileSystemModel

from dcp_client.utils import settings

if TYPE_CHECKING:
from dcp_client.app import Application
Expand Down Expand Up @@ -98,8 +99,9 @@ def __init__(self, app: Application) -> None:

super().__init__()
self.app = app
self.title = "Data Overview"
self.title = "DCP: Data Overview"
self.worker_thread = None
self.accepted_types = ['*'+end for end in settings.accepted_types]
self.main_window()

def main_window(self) -> None:
Expand Down Expand Up @@ -137,6 +139,8 @@ def main_window(self) -> None:
self.eval_dir_layout.addWidget(self.label_eval)
# add eval dir list
model_eval = MyQFileSystemModel(app=self.app)
model_eval.setNameFilters(self.accepted_types)
model_eval.setNameFilterDisables(False) # Enable the filters
model_eval.setIconProvider(IconProvider())
model_eval.sort(0, Qt.AscendingOrder)

Expand Down Expand Up @@ -194,6 +198,8 @@ def main_window(self) -> None:
self.inprogr_dir_layout.addWidget(self.label_inprogr)
# add in progress dir list
model_inprogr = MyQFileSystemModel(app=self.app)
model_inprogr.setNameFilters(self.accepted_types)
model_inprogr.setNameFilterDisables(False) # Enable the filters
# self.list_view = QListView(self)
self.list_view_inprogr = QTreeView(self)
self.list_view_inprogr.setToolTip("Select an image, click it, then press Enter")
Expand Down Expand Up @@ -241,6 +247,8 @@ def main_window(self) -> None:
self.train_dir_layout.addWidget(self.label_train)
# add train dir list
model_train = MyQFileSystemModel(app=self.app)
model_train.setNameFilters(self.accepted_types)
model_train.setNameFilterDisables(False) # Enable the filters
# self.list_view = QListView(self)
self.list_view_train = QTreeView(self)
self.list_view_train.setToolTip("Select an image, click it, then press Enter")
Expand Down
16 changes: 8 additions & 8 deletions src/client/dcp_client/gui/welcome_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,21 @@ def __init__(self, app: Application) -> None:
"""
super().__init__()
self.app = app
self.setWindowTitle("Welcome to Helmholtz AI Data-Centric Tool")
self.setWindowTitle("DCP")
self.setStyleSheet("background-color: #f3f3f3;")
self.resize(590, 250)

self.main_layout = QVBoxLayout()

title_label = QLabel("Welcome to Helmholtz AI Data-Centric Tool")
title_label = QLabel("Welcome to the Helmholtz AI Data-Centric Tool!")
title_label.setAlignment(Qt.AlignCenter)
title_label.setStyleSheet(
"font-size: 24px; font-weight: bold; color: #015998;"
"font-size: 20px; font-weight: bold; color: #015998;"
)
self.main_layout.addWidget(title_label)

instructions_label = QLabel("Please select your dataset folder:")
instructions_label.setAlignment(Qt.AlignCenter)
instructions_label = QLabel("Please select your dataset folders:")
instructions_label.setAlignment(Qt.AlignLeft)# AlignCenter)
instructions_label.setStyleSheet(
"font-size: 14px; color: #000000;"
)
Expand All @@ -62,13 +62,13 @@ def __init__(self, app: Application) -> None:
self.button_layout = QVBoxLayout()

val_label = QLabel(self)
val_label.setText('Uncurated dataset path:')
val_label.setText('Uncurated dataset:')


inprogr_label = QLabel(self)
inprogr_label.setText("Curation in progress path:")
inprogr_label.setText("In progress directory:")
train_label = QLabel(self)
train_label.setText('Curated dataset path:')
train_label.setText('Curated dataset:')


self.text_layout.addWidget(val_label)
Expand Down

0 comments on commit 9f66d7d

Please sign in to comment.