I have two microscope images. One in gray scale, one in red. I can merge these in photoshop, imagej, etc. I want to merge these two in opencv so I can perform this operation on many samples.
So far I’ve done the following (where dia=grayscale and epi=red).
# Load images
img_dia = cv2.imread(input_dia)
img_epi = cv2.imread(input_epi)
# Slice red channel from fluorescence image
b_epi, g_epi, r_epi = cv2.split(img_epi)
# Now I want to merge the grey scale and red image
No error messages. I could not find any documentation or other stack exchange pages to resolve this issue. Any help would be appreciated!
2
Answers
considering
input_epi
is an RGB image(3 channels)when you load an image into opencv it is loaded as BGR by default
Splitting and Merging Image Channels
In OpenCV Documentation
Warning cv2.split() is a costly operation (in terms of time). So do it only if you need it. Otherwise go for Numpy indexing.
Actual red colour is tricky to pin point from a
RGB
image better to useHSV
to extract particular range of colour from an imageThere are many ways of overlaying and blending images, but I think the nearest result to yours is probably screen-mode blending.
You can get what you want quite simply with ImageMagick which is included in most Linux distros and is available for macOS and Windows. So, just in Terminal (or Command Prompt on Windows), you can run the following without needing to write any code:
If that is not the exact blend-mode you want, there 69 modes available in ImageMagick and you can see them all listed if you run:
So, if you want Hard Light blending, use:
You alluded to having lots of images to do, if so, you can get thousands done in parallel just by using GNU Parallel. You can search for answers on Stack Overflow that use ImageMagick and GNU Parallel by putting the following in the Stack Overflow Search box, including the square brackets:
Or, provide some more detail on how your files are named and stored and I can help you further.