From: shilpa khinvasara on 5 Aug 2010 06:10 sir, i have hsv image which is quantized to 166 bins now i want to find the occurence of each color in those bins and find its mean
From: ImageAnalyst on 5 Aug 2010 07:22 On Aug 5, 6:10 am, "shilpa khinvasara" <s...(a)gamil.com> wrote: > sir, > i have hsv image which is quantized to 166 bins > now i want to find the occurence of each color in those bins and find its mean --------------------------------------------------------------------------- Finding the mean and histograms of hsv images done in one of my demos. The only thing you have to add is to use the conv2() function to get the mean in 3x3 window (which is totally unnecessary and redundant so I don't know why you're doing it - it's like you're taking the average twice). % function rgb2hsv_Demo() % Change the current folder to the folder of this m-file. % (The line of code below is from Brett Shoelson of The Mathworks.) if(~isdeployed) cd(fileparts(which(mfilename))); end clc; % Clear command window. clear; % Delete all variables. close all; % Close all figure windows except those created by imtool. imtool close all; % Close all figure windows created by imtool. workspace; % Make sure the workspace panel is showing. fontSize = 20; % Create a figure for our images. figure; set(gcf, 'Position', get(0,'Screensize')); % Maximize figure. % Read in standard MATLAB color demo images. imagesFolder = 'C:\Program Files\MATLAB\R2010a\toolbox\images \imdemos'; filePattern = [imagesFolder, '\*.jpg']; % Read the directory to get a list of images. jpegFiles = dir(filePattern); numberOfImagesProcessed = 0; numberOfImagesToProcess = length(jpegFiles); % Loop though all images, converting to hsv and then getting the means % of the h, s, and v channels. hImage_Mean = zeros(numberOfImagesToProcess, 1); sImage_Mean = zeros(numberOfImagesToProcess, 1); vImage_Mean = zeros(numberOfImagesToProcess, 1); for k = 1 : numberOfImagesToProcess % Read in this one file. baseFileName = jpegFiles(k).name; fullFileName = fullfile(imagesFolder, baseFileName); rgbImage = imread(fullFileName); subplot(2, 3, 1); imshow(rgbImage, []); title('Original color Image', 'FontSize', fontSize); % Convert to floating point so it does the calculations correctly. % Also needs to be normalized to 0-1. rgbFloating = double(rgbImage) / 255.0; % Resize it to be 32 pixels by 32 pixels. % rgbFloating = imresize(rgbFloating, [32 32]); % subplot(2, 3, 2); % imshow(rgbFloating, []); % Display the image. % title('Scaled down 32x32 color Image', 'FontSize', fontSize); % Compute hsv image hsvImage = rgb2hsv(rgbFloating); % H image: hImage = hsvImage(:,:,1); subplot(2, 3, 4); imshow(hImage, []); % Display the image. % Compute mean hImage_Mean(k) = mean(hImage(:)); caption = sprintf('H Image. Mean = %6.2f', hImage_Mean(k)); title(caption, 'FontSize', fontSize); % S image: sImage = hsvImage(:,:,2); subplot(2, 3, 5); imshow(sImage, []); % Display the image. % Compute mean sImage_Mean(k) = mean(sImage(:)); caption = sprintf('S Image. Mean = %6.2f', sImage_Mean(k)); title(caption, 'FontSize', fontSize); % V image: vImage = hsvImage(:,:,3); subplot(2, 3, 6); imshow(vImage, []); % Display the image. numberOfImagesProcessed = numberOfImagesProcessed + 1; % Compute mean vImage_Mean(k) = mean(vImage(:)); caption = sprintf('V Image. Mean = %6.2f', vImage_Mean(k)); title(caption, 'FontSize', fontSize); % Prompt user to continue. promptMessage = sprintf('Currently displaying image #%d of %d:\n%s \nDo you want to Continue processing,\nor Cancel to abort processing?',... numberOfImagesProcessed, numberOfImagesToProcess, baseFileName); button = questdlg(promptMessage, 'Continue', 'Continue', 'Cancel', 'Continue'); if strcmp(button, 'Cancel') break; end end % Crop off any unassigned values: hImage_Mean = hImage_Mean(1:numberOfImagesProcessed); sImage_Mean = sImage_Mean(1:numberOfImagesProcessed); vImage_Mean = vImage_Mean(1:numberOfImagesProcessed); % Print to command window fprintf(1, ' Filename, H Mean, S Mean, V Mean\n'); for k = 1 : length(hImage_Mean) baseFileName = jpegFiles(k).name; fprintf(1, '%24s %6.2f, %6.2f, %6.2f\n', ... baseFileName, hImage_Mean(k), sImage_Mean(k), vImage_Mean(k)); end caption = sprintf('Done with demo!\n\nProcessed %d images.\nCheck out the command window for the results', numberOfImagesProcessed); msgbox(caption);
|
Pages: 1 Prev: Eliminating negative zeros in a matrix Next: Simulink change scope background color |