I have calculate the color histogram values of 30 images in a database. Now i want to calculate the local color histogram values of images dividing the image into 4 equal parts.How i proceed using the following code?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
srcFiles=dir('fruits\*.jpg');
for i= 1:length(srcFiles)
disp(i);
Filename=strcat('fruits\',srcFiles(i).name);
I=imread(Filename);
%imresize(I, [177 284])
imshow(I),figure
[index, map]=rgb2ind(I,65300);
pixels= prod(size(index));
hsv=rgb2hsv(map);
h = hsv(:,1);
s = hsv(:,2);
v = hsv(:,3);
darks = find(v <.2)';
lights = find(s < .05 & v > .85)';
h([darks lights])= -1;
disp(length(darks))
black = length(darks)/pixels;
white = length(lights)/pixels;
red = length(find((h >.9167 | h <=.083) & h~=-1))/pixels;
yellow=length(find(h >.083 & h<=.25))/pixels;
green=length(find(h > .25 & h<= .4167))/pixels;
cyan= length(find(h > .4167 & h<= .5833))/pixels;
blue=length(find(h > .5833 & h <= .75))/pixels;
magenta=length(find(h > .75 & h <= .9167))/pixels;
disp('Red=')
disp(red)
disp('Blue=')
disp(blue)
a(i,1)=red
a(i,2)=green
a(i,3)=blue
a(i,4)=yellow
a(i,5)=cyan
a(i,6)=magenta
a(i,7)=black
a(i,8)=white
end
dlmwrite('frs.mat',a)
b=dlmread('frs.mat')
%c={'red','green','blue','yellow','cyan','magenta','black','white'}
%f={c;a}
%snames = nominal({'10.jpg';'11.jpg';'12.jpg';'13.jpg';'14.jpg';'15.jpg';'16.jpg';'17.jpg';'18.jpg';'19.jpg';'20.jpg';'21.jpg';'22.jpg';'23.jpg';'24.jpg';'25.jpg';'26.jpg';'27.jpg';'28.jpg';'29.jpg';'30.jpg';'31.jpg';'32.jpg';'33.jpg';'34.jpg'});
%f = dataset({snames,'images'},{[a(i,1);a(i,2);a(i,3);a(i,4);a(i,5);a(i,6);a(i,7);a(i,8)],'f'})
hold on
fill([0 0 1 1], [0 red red 0], 'r')
fill([1 1 2 2],[0 yellow yellow 0], 'y')
fill([2 2 3 3],[0 green green 0], 'g')
fill([3 3 4 4],[0 cyan cyan 0], 'c')
fill([4 4 5 5],[0 blue blue 0], 'b')
fill([5 5 6 6],[0 magenta magenta 0], 'm')
fill([6 6 7 7],[0 white white 0], 'w')
fill([7 7 8 8],[0 black black 0], 'k')
axis([0 8 0 1])
%fr=strcat('features_',Filename,'.mat');
Antworten (1)
Image Analyst
am 20 Jun. 2014
Divide the image up into 4 individual color channels:
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
Then see David's answer for dividing the image into 4 quadrants: http://www.mathworks.com/matlabcentral/answers/136640#answer_141764 and call imhist() for each quadrant of each color channel.
2 Kommentare
Siehe auch
Kategorien
Mehr zu Histograms finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!