Can I use image processing to compare color of a bag with a provided standard bag photo?

1 次查看(过去 30 天)
Hi,
I have a problem of quality inspection of color of product packaging bag. I am provided with three standard bags, one is the bag of acceptable color, the other two are its high and low shades or simply the range in whcih a consignmnet can be accepted. The problem is, each person has his own persection of color and decides on basis of his perception that wather this sample bag is within the acceptable color range or not, by comparing all 4 bags (3 standard bags and 1 sample) visually in a fixed lighting condition.
I am curious that is there a way that I could use matlab image processing for the above task and a program will tell us that under iinspection bag color is acceptable or not?
Thanks

回答(1 个)

Satyam
Satyam 2025-6-17
To address the subjectivity in visual color inspection of product packaging bags, we can implement a MATLAB-based image processing solution. We have already been provided with three reference images, a target shade and its acceptable high and low color variants, against which a sample bag is compared.
We can formulate an approach which evaluates the sample by analysing the mean RGB values within a central region of interest (ROI) in the image. It checks whether the sample's RGB values lie within the range defined by the high and low reference shades. If so, the sample is accepted; otherwise, it is rejected. You can leverage ‘mean’ function of MATLAB to compute mean RGB values. Refer to the documentation of ‘mean’ function to know more about the syntax and its usage: https://in.mathworks.com/help/matlab/ref/double.mean.html
Below is a code snippet demonstrating the above approach:
% Compute mean RGB values
mean_low = mean(reshape(low_roi, [], 3));
mean_high = mean(reshape(high_roi, [], 3));
mean_target = mean(reshape(target_roi, [], 3));
mean_sample = mean(reshape(sample_roi, [], 3));
% Check if sample RGB is within acceptable bounds
R_in = mean_sample(1) >= min(mean_low(1), mean_high(1)) && mean_sample(1) <= max(mean_low(1), mean_high(1));
G_in = mean_sample(2) >= min(mean_low(2), mean_high(2)) && mean_sample(2) <= max(mean_low(2), mean_high(2));
B_in = mean_sample(3) >= min(mean_low(3), mean_high(3)) && mean_sample(3) <= max(mean_low(3), mean_high(3));
if R_in && G_in && B_in
result = 'ACCEPTED';
else
result = 'REJECTED';
end
I hope it helps.

类别

Help CenterFile Exchange 中查找有关 Lighting, Transparency, and Shading 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by