Clear Filters
Clear Filters

Working with RGB images

1 view (last 30 days)
Fedor Durnev
Fedor Durnev on 25 Jul 2019
Commented: KALYAN ACHARJYA on 26 Jul 2019
I have a bunch of photos. Each photo I should divide into R,G and B channels (this part I completed successfully). Then I need to calculate average value of R, G and B for each photo (calculate average R for R photos, G for G photos, etc.) and build plots where X is number a photo, Y is average value of color). So there are 2 problems:
  1. How do I create cycle in this case?
  2. How do I count this average values and then build 3 plots? ( I guess I should write down all values into matrix and then build plots but I am quite unexperienced in Matlab, so there are problems with writing appropriate Matlab code).
Many thanks!

Accepted Answer

KALYAN ACHARJYA
KALYAN ACHARJYA on 25 Jul 2019
Edited: KALYAN ACHARJYA on 25 Jul 2019
  1. "How do I create cycle in this case?"
Loop as discussed in below
  1. 2. "How do I count this average values and then build 3 plots?"
Lets say, R_plane,G_plane and B_plane are the R,G,B plane of RGB image (You mentioned: this part I completed successfully), Average
r_average=mean(R_plane(:));
g_average=mean(G_plane(:));
b_average=mean(B_plane(:));
For do the same of multiple images, you are advised the call images one by one and save the average values in array. To call the multiple images one by one and do operation, please see my this answer.
for ..inside
r_average(i)=mean(R_plane(:));
g_average(i)=mean(G_plane(:));
b_average(i)=mean(B_plane(:));
end
Now
r_average, g_average, and b_average are three array, with size total number of images. Now you can do Bar plot (x images number and y as average number of corresponding image), outside the loop
r_average=[];
g_average=[];
b_average=[];
InputImages=....
for ..inside
r_average(i)=mean(R_plane(:));
g_average(i)=mean(G_plane(:));
b_average(i)=mean(B_plane(:));
end
subplot(131), bar(r_average);
subplot(132), bar(g_average);
subplot(133), bar(b_average);
or if you insisted to use plot
x_data=[1:length(InputImages)];
subplot(131), plot(x_data,r_average);
subplot(132), plot(x_data,g_average);
subplot(133), plot(x_data,b_average);
Or see stem
Hope I understand your question.
Good Luck!
  4 Comments
Fedor Durnev
Fedor Durnev on 26 Jul 2019
Great! Thanks a lot!
KALYAN ACHARJYA
KALYAN ACHARJYA on 26 Jul 2019
You're welcome!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!