-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfiltrage.py
87 lines (64 loc) · 2.33 KB
/
filtrage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# -*- coding: utf-8 -*-
"""
Created on Fri Jun 2 12:34:31 2023
@author: 33606
"""
import numpy as np
def list_filtrage(label):
"""
Filter a label list and return the indices of images with all-zero labels.
Args:
label (numpy.ndarray): List of labels with shape (num_images, height, width).
Returns:
list: List of indices corresponding to images with all-zero labels.
"""
# Calculate the number of images
nb_images = np.shape(label)[0]
# Get the dimensions of the label
dim = np.shape(label)[1], np.shape(label)[2]
# Initialize an empty list
L = []
# Reshape the label array
M_bis = np.reshape(label, (nb_images, dim[0], dim[1], 1))
# Iterate over the images
for i in range(nb_images):
# Check if any value in the image is non-zero
if not np.any(M_bis[i, :, :, :]):
# Append the index to the list
L.append(i)
return L
def filtrage(data, label, L):
"""
Filter data and labels based on the indices to keep.
Args:
data (numpy.ndarray): Data array with shape (num_images, height, width).
label (numpy.ndarray): Label array with shape (num_images, height, width).
L (list): List of indices to keep.
Returns:
numpy.ndarray: Filtered data array.
numpy.ndarray: Filtered label array.
"""
# Calculate the number of images
nb_images = np.shape(label)[0]
# Get the dimensions of the label
dim = np.shape(label)[1], np.shape(label)[2]
# Reshape the label array
label = np.reshape(label, (nb_images, dim[0], dim[1]))
# Initialize new arrays for filtered data and labels
data_f = np.zeros((nb_images - len(L), dim[0], dim[1]))
label_f = np.zeros((nb_images - len(L), dim[0], dim[1]))
# Initialize a counter
j = 0
# Iterate over the images
for i in range(nb_images):
# Check if the index is not in the list of indices to exclude
if i not in L:
# Copy the data and label to the filtered arrays
data_f[j, :, :] = data[i, :, :]
label_f[j, :, :] = label[i, :, :]
j += 1
return data_f, label_f
#data=np.load('')
#label=np.load('')
#L=list_filtrage(label)
#data_f, label_f=filtrage(data, label, L)