-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMask_Maker.py
More file actions
36 lines (34 loc) · 1.59 KB
/
Mask_Maker.py
File metadata and controls
36 lines (34 loc) · 1.59 KB
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
import numpy as np
import torch
def GetLocalImage(images, local_x, local_y):
#원본이미지에서 일부분을 크롭합니다.
diff_x = local_x-65
local_x[diff_x <0] =local_x[diff_x <0] -diff_x[diff_x <0]
diff_x = local_x-191#256- 64 =192
local_x[diff_x >0] =local_x[diff_x >0] -diff_x[diff_x >0]
diff_y = local_y-65
local_y[diff_y <0] =local_y[diff_y <0] -diff_y[diff_y <0]
diff_y = local_y-191
local_y[diff_y >0] =local_y[diff_y >0] -diff_y[diff_y >0]
cropped_image = images[0,:,local_y[0,0]-64:local_y[0,0]+64,local_x[0,0]-64:local_x[0,0]+64]
cropped_image = torch.unsqueeze(cropped_image,0)
for i in range(1,images.size(0)):
temp_image = images[i,:,local_y[i,0]-64:local_y[i,0]+64,local_x[i,0]-64:local_x[i,0]+64]
temp_image = torch.unsqueeze(temp_image,0)
cropped_image = torch.cat([cropped_image,temp_image],dim=0)
return cropped_image
def ImageSum(InputImage, Mask, RealImage):
'''
256*256 이미지
>>> image[test<3] =0
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IndexError: The shape of the mask [2, 2, 2] at index 1 does not match the shape of the indexed tensor [2, 3, 2, 2] at index 1
'''
triple_mask = Mask.expand(-1,3,-1,-1)# batch 1*width height로 늘리고, 차원을 3차원으로 늘림 -> 이미 배치로 나오면서 차원이 늘어나있음
ReturnImage = InputImage.clone()
ReturnImage[triple_mask ==0] = 0#마스킹연산
RealImage_copy =RealImage.clone()
RealImage_copy[triple_mask ==1] = 0#반대로 마스킹
ReturnImage = torch.add(ReturnImage,RealImage_copy)# 더하기 연산
return ReturnImage