Skip to content

Commit

Permalink
examples+fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Rubiksman78 committed Mar 11, 2023
1 parent 1f772a4 commit 700eee7
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,23 @@ Launch `haircolorchange.bat` to execute the script.

### Linux/MacOS installation

Clone the repository.
Clone the repository: `git clone https://github.com/Rubiksman78/MAS-Hair-Color-Change.git`.

Install the requirements with `pip install -r requirements.txt`.

Launch the script with `python hair_color_change.py`

## Usage

The script will overwrite the hair files in the `game/mod_assets/monika/h` folder and make a backup of the original files as a file `hair_name-backup.png` in the same folder. If you want to restore the original hair color, just delete the modified files and delete the `-backup` in the name of the backup files.

It modifies the color by pair automatically, because for each haircut there are two files, one for the front and one for the back of the hair.

Example: `hair-down-front-backup.png` is the backup of `hair-down-front.png` and `hair-down-front.png` is the modified file. The same applies to the back of the hair.

To modify the color, you can set three trackbars:
- Hue: changes the color of the hair
- Saturation: changes the saturation of the hair
- Value: changes the brightness of the hair

![Trackbars](images/example.png)
17 changes: 6 additions & 11 deletions hair_color_change.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,10 @@

mask_front = im_front[:,:,3] > 0
inverse_mask_front = im_front[:,:,3] == 0
color_mask_front = np.ones_like(im_front, dtype=np.float32)

mask_back = im_back[:,:,3] > 0
inverse_mask_back = im_back[:,:,3] == 0
color_mask_back = np.ones_like(im_back, dtype=np.float32)

#put all the rest to black
color_mask_front[~mask_front] = [0, 0, 0, 0]
color_mask_back[~mask_back] = [0, 0, 0, 0]
def nothing(x):
pass

Expand Down Expand Up @@ -111,7 +106,6 @@ def nothing(x):

bit_inverse_mask_front = np.stack((inverse_mask_front,)*3, axis=-1)
bit_inverse_mask_back = np.stack((inverse_mask_back,)*3, axis=-1)
print(np.sum(bit_mask_front==True),np.sum(bit_mask_front==False))

h_front, s_front, v_front = cv2.split(hsv_front)
h_back, s_back, v_back = cv2.split(hsv_back)
Expand Down Expand Up @@ -164,14 +158,15 @@ def nothing(x):
answer = messagebox.askyesno("Save changes", "Do you want to save the changes?")
root.destroy()

print(answer)
if answer == False:
im_front = im_backup_front/255
im_back = im_backup_back/255
im_front = im_backup_front
im_back = im_backup_back

#save image and backup
cv2.imwrite(file_back, im_back*255)
cv2.imwrite(file_front, im_front*255)

print(im_back.shape)
cv2.imwrite(file_back, im_back)
cv2.imwrite(file_front, im_front)
if not os.path.isfile(file + '-back-backup.png') and not os.path.isfile(file + '-front-backup.png') and answer == True:
cv2.imwrite(file + '-back-backup.png', im_backup_back)
cv2.imwrite(file + '-front-backup.png', im_backup_front)
Expand Down
Binary file added images/example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
opencv-python
tk
numpy

0 comments on commit 700eee7

Please sign in to comment.