Hi Tim,
I understand that you are seeking a method to correct the brightness and contrast across entire set of images to ensure that the background colour is consistent before they proceed with their main analysis. This preprocessing step is crucial for ensuring that any quantification or comparison made is based on the objects of interest rather than being skewed by variations in the image background.To address this issue, one needs to employ image processing techniques that can adjust the brightness and contrast of the images in a uniform manner. Please refer to the following steps:
Step 1: Read the Images
Assuming one has a set of images stored in directory, then can loop through each image file, read it, and apply the necessary adjustments. First, start by reading an image:
img = imread('path_to_your_image.jpg');
Step 2: Convert to a Suitable Colour Space (Optional)
If images are in RGB colour space and one is mainly interested in the brightness and contrast, converting them to a different colour space (like HSV or LAB) might make the adjustments more straightforward. For instance, in the HSV colour space, the V channel represents the image's brightness. However, for general brightness and contrast adjustments, staying in the RGB colour space might suffice.
Step 3: Adjust Brightness and Contrast
MATLAB “imadjust” function can be used to adjust the contrast of images. If need to adjust the brightness, addor subtract a constant value from the image or use “imadjust”. For a simple contrast adjustment in RGB:
adjustedImg = imadjust(img, [low_in; high_in], [low_out; high_out]);
- low_in and high_in are the intensity ranges of the input image to map from, typically between 0 to 1 for floating-point images or 0 to 255 for uint8 images.
- low_out and high_out are the output ranges.
To adjust brightness, add or subtract a value:
brightenedImg = img + brightnessFactor;
brightenedImg = uint8(brightenedImg);
Step 4: Apply Adjustments to All Images
Put the above steps in a loop to process multiple images. For example:
files = dir('path_to_your_images/*.jpg');
imgPath = fullfile(files(i).folder, files(i).name);
adjustedImg = imadjust(img);
imwrite(adjustedImg, ['Adjusted_' files(i).name]);
Step 5: Analyse the adjusted Images
Once all images are adjusted for brightness and contrast, proceed with analysis, such as quantifying areas of interest. Since the images are now normalized in terms of lighting conditions, analysis should be more consistent across the set.
Remember, the effectiveness of these adjustments can depend on the specifics of images and what one is trying to achieve. here might be a need to experiment with different methods and parameters to get best results. Please refer to the following documentation links:
- imread-https://www.mathworks.com/help/matlab/ref/imread.html?searchHighlight=imread&s_tid=srchtitle_support_results_1_imread
- imadjust- https://www.mathworks.com/help/images/ref/imadjust.html?searchHighlight=imadjust&s_tid=srchtitle_support_results_1_imadjust
- double- https://www.mathworks.com/help/matlab/ref/double.html?searchHighlight=double&s_tid=srchtitle_support_results_1_double
- fullfile- https://www.mathworks.com/help/matlab/ref/fullfile.html?searchHighlight=fullfile&s_tid=srchtitle_support_results_1_fullfile
- imwrite- https://www.mathworks.com/help/matlab/ref/imwrite.html?searchHighlight=imwrite&s_tid=srchtitle_support_results_1_imwrite
- for- https://www.mathworks.com/help/matlab/ref/for.html?searchHighlight=for&s_tid=srchtitle_support_results_1_for
Hope it helps!
Best Regards,
Simar