bowang-lab / BLEEP

Spatially Resolved Gene Expression Prediction from H&E Histology Images via Bi-modal Contrastive Learning
Apache License 2.0
63 stars 10 forks source link

About the patches #11

Closed Yoyiming closed 1 month ago

Yoyiming commented 1 month ago

@Xrioen @subercui Hello, I think there might be an issue in dataset.py. When cropping patches, the pixel values for the x-axis should correspond to the width of the image, but I noticed that the code might be treating it as the height. Since the image loaded by OpenCV should have dimensions in HWC format, I believe this might be the cause.

v1 = self.spatial_pos_csv.loc[self.spatial_pos_csv[0] == barcode,4].values[0] v2 = self.spatial_pos_csv.loc[self.spatial_pos_csv[0] == barcode,5].values[0] image = self.whole_image[(v1-112):(v1+112),(v2-112):(v2+112)]

where v1 refers to x-axis and v2 refers to y-axis.

Xrioen commented 1 month ago

Hi Yoyiming, the x and y coordinates of the spatial_pos_csv is also in the same format as OpenCV, hence the two cancels out.

import matplotlib.pyplot as plt
import cv2
import pandas as pd

spatial_pos_csv = pd.read_csv("GSM7697868_C73A1_tissue_positions_list.csv", sep=",", header = None)
whole_image = cv2.imread("GSM7697868_GEX_C73_A1_Merged.tiff")
filter = spatial_pos_csv.loc[:,1] == 1
x = spatial_pos_csv.loc[filter,4].values
y = spatial_pos_csv.loc[filter,5].values

for i in range(len(x)):
    whole_image[x[i]-112:x[i]+112,y[i]-112:y[i]+112] = 0

plt.imshow(whole_image)