Image compare and correction

19 visualizaciones (últimos 30 días)
tim pearce
tim pearce el 26 de Feb. de 2024
Comentada: tim pearce el 8 de Mzo. de 2024
Hi, I’m trying to compare some images they were taken under specific conditions against a blue background with the same lighting source at the same angle and distance I want to compare the object in the image but before I do that I’ve noticed the background is varies in the shade of blue. I’m wondering if I can first correct the whole set for brightness and contrast before I put them into my script to quantify the actual area of interest

Respuestas (1)

Simar
Simar el 6 de Mzo. de 2024
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:
img = double(img); % Convert to double for manipulation
brightnessFactor = 20; % Adjust this value as needed
brightenedImg = img + brightnessFactor;
brightenedImg = uint8(brightenedImg); % Convert back to uint8 if necessary
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'); % Adjust the path and file type
for i = 1:length(files)
imgPath = fullfile(files(i).folder, files(i).name);
img = imread(imgPath);
% Adjust brightness and contrast here
% For example, using imadjust:
adjustedImg = imadjust(img); % Customize as needed
% Save the adjusted image
imwrite(adjustedImg, ['Adjusted_' files(i).name]);
end
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
  1 comentario
tim pearce
tim pearce el 8 de Mzo. de 2024
Fantastic a clear answer with a nice route for me to try Thank you I look forward to playing with this Tim

Iniciar sesión para comentar.

Productos


Versión

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by