Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Color-matcher batch processing #1

Closed
SahPet opened this issue Dec 21, 2020 · 4 comments
Closed

Color-matcher batch processing #1

SahPet opened this issue Dec 21, 2020 · 4 comments

Comments

@SahPet
Copy link

SahPet commented Dec 21, 2020

I've just discovered color-matcher and find it potentially very useful for preprocessing histopathological datasets for deep learning. I can't, however, find a way to use it in batch mode - that is - is there any way to load more than one source image and/or more than one target image to process larger image datasets in batch?

@hahnec
Copy link
Owner

hahnec commented Dec 21, 2020

I am glad this tool may be useful for medical applications. So far, I have considered batch processing from the command line, which was supposed to work when providing the source directory as follows:

color-matcher -s './tests/data/' -r './tests/data/scotland_plain.png'

However, I figured that each output file gets overriden due to identical filename creation. I fixed this issue in v0.3.2, which is now available via pip install color-matcher==0.3.2

Similar to the Jupyter notebook example, you can alternatively use the API to iterate through your image stack via a single loop like the one below:

from color_matcher import ColorMatcher
from color_matcher.io_handler import load_img_file, save_img_file, FILE_EXTS
from color_matcher.normalizer import Normalizer
import os

img_ref = load_img_file('./tests/data/scotland_plain.png')

src_path = '.'
filenames = [os.path.join(src_path, f) for f in os.listdir(src_path)
                     if f.lower().endswith(FILE_EXTS)]

for i, fname in enumerate(filenames):
	img_src = load_img_file(fname)
	obj = ColorMatcher(src=img_src, ref=img_ref, method='mkl')
	img_res = obj.main()
	img_res = Normalizer(img_res).uint8_norm()
	save_img_file(img_res, os.path.join(os.path.dirname(fname), str(i)+'.png'))

Let me know whether this helps or if you still encounter issues.

Best,
Chris

@SahPet
Copy link
Author

SahPet commented Dec 21, 2020

Thank you so much, Chris! I'll try it soon. Tried photoshops "match color" function, and I think color-matcher did a better job.

@Menante
Copy link

Menante commented Jan 2, 2021

Thank you so much, It works perfectly! (I used it for own personal small software for my scansions of ancient books, which had to be normalized)

@hahnec
Copy link
Owner

hahnec commented Feb 21, 2021

Glad, it works on your side!

@hahnec hahnec closed this as completed Feb 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants