Thread Subject: Image Classification

Subject: Image Classification

From: Manju

Date: 23 Jan, 2009 06:47:02

Message: 1 of 4

I want to reduce the size of color image.i want to fix the size (45*47) of color image..
plz help me out.

Subject: Image Classification

From: Walter Roberson

Date: 23 Jan, 2009 16:06:30

Message: 2 of 4

Manju wrote:
> I want to reduce the size of color image.i want to fix the size (45*47) of color image..
> plz help me out.

If you have the image processing toolbox, then imresize()

There are numerous methods of resizing images, and the proper one for your
application will depend upon which properties you wish to preserve.
For example in some applications it is important to preserve edges
when the image is resized, but many of the simpler methods of image
resizing tend to blur edges.

If you have not been given any criteria as to what is important to preserve
or not, then to do the resizing, use this code:

imsize = size(TheImage);
sx = imsize(1); sy = imsize(2);
if sx < 45 || sy < 47
  error('image is too small to resize to 45 x 47');
end
rx = ceil((sx - 45) * rand);
ry = ceil((sy - 47) * rand);
NewImage = TheImage(rx:rx+44, ry:ry+46,:);


--
.signature note: I am now avoiding replying to unclear or ambiguous postings.
Please review questions before posting them. Be specific. Use examples of what you mean,
of what you don't mean. Specify boundary conditions, and data classes and value
relationships -- what if we scrambled your data or used -Inf, NaN, or complex(rand,rand)?

Subject: Image Classification

From: Manju

Date: 24 Jan, 2009 05:48:02

Message: 3 of 4

Thanks a lot sir,

Now i want average RGB values were calculated in five zones of the images, corresponding to the left, right, top, bottom, and center parts of the image area.
        Circle zone is one fofth of whole image.&remening four zones is divided by four.
       This resulted to 15-dimensional vectors.so first of all i want divide the image in five zone....

Subject: Image Classification

From: Manju

Date: 24 Jan, 2009 05:56:02

Message: 4 of 4

hi, all
this is my code for color histogram...how can i used this code in image classification by neural network..


function createColorHistograms(im_str)

if ~isstr(im_str)
    if ndims(im_str)==3
        try
            col_array_vals=double(im_str);
        catch
            disp('Input is not a valid three-dimensional array');
            return;
        end
    end
else
    try
        col_array_vals=double(imread(im_str));
        if ndims(col_array_vals)~=3
            disp('Input is not a valid three-dimensional array');
            return;
        end

    catch
        disp('Input string does not point to a valid image file');
        return;
    end
end



%===
%res_val: Binning resolution. Increasing the value gives coarsers bins
%===
res_val=25;



%===
%t_count: Color triplets are converted to a single value for purposes of
%binning
%===
t_count=res_val*floor(col_array_vals(:,:,1)/res_val)+256*(res_val*floor(col_array_vals(:,:,2)/res_val))+256*256*(res_val*floor(col_array_vals(:,:,3)/res_val));
t_count=sort(t_count(:));

%===
% Use unique to calculate the number of triplets (ind_last-ind_first) in each bin
%===
[col_val,ind_first]=unique(t_count,'first');
[col_val,ind_last]=unique(t_count,'last');

disp('Drawing color bars')
colorbars(col_val,ind_last-ind_first,1/3,1/4)
% disp('Drawing color cloud')
% colorcloud(col_val,ind_last-ind_first,1/3,1/4)
disp('Drawing image')
figure(3)
set(gcf,'position',[5 61 274 236]);
imshow(col_array_vals/255)


function colorbars(triplet_color,triplet_freq,varargin)

if nargin==2
    color_pow=1/3;
    freq_pow=1/4;
else
    color_pow=varargin{1};
    freq_pow=varargin{2};
end


%===
% Randomize bin ordering
%===
N_rand=randperm(length(triplet_freq));
triplet_freq=sqrt(triplet_freq(N_rand));
triplet_color=triplet_color(N_rand);


%===
% Reconstruct color triplets from col_val
% Sphere triplets
%===
triplet_color=([rem(triplet_color,256) floor(rem(triplet_color,256*256)/256) floor(triplet_color/(256*256))]/255);
triplet_color_norm=triplet_color./repmat(((sum(triplet_color.^(1),2))+.005),1,3);
max(triplet_color_norm)
triplet_diff=sum(abs(triplet_color_norm-repmat(triplet_color_norm(end,:),size(triplet_color_norm,1),1)),2);
%===
% colors are sorted with red [.9 0 0] as the anchor
%===
triplet_diff=sum(abs(triplet_color_norm-repmat([.9 0 0],size(triplet_color_norm,1),1)),2);

max(triplet_diff)
%===
% color_pow and freq_pow are used to obtain a suitable spacing of colors
% Ordering of a triplet in 2-d gives us an extra degree of freedom.
% How do we use this to align perceptual distance and euclidean distance?
%===
triplet_diff=(triplet_diff/max(triplet_diff).^(color_pow))+(triplet_freq*0).^(freq_pow);



[d,inds_sort]=sort(triplet_diff);
triplet_freq=(triplet_freq(inds_sort));
triplet_color=(triplet_color(inds_sort,:));

num_bars=length(triplet_color);
max_val=max(triplet_freq);

close all;
figure(1);
axis([0 num_bars 0 1]);

for i=1:num_bars
    tempColor=min(triplet_color(i,:),.9);
    %===
    % Use patch to draw individual bars
    %===

    patch([i-1 i-1 i i],...
        [0 triplet_freq(i)/(max_val+1) triplet_freq(i)/(max_val+1) 0],...
        tempColor,...
        'edgecolor',...
        tempColor);
end

set(gca,'xticklabel','')
set(gca,'yticklabel','')
set(gcf,'position',[5 378 560 420]);
set(gca,'visible','off')



function colorcloud(triplet_color,triplet_freq,varargin)

if nargin==2
    color_pow=1/3;
    freq_pow=1/4;
else
    color_pow=varargin{1};
    freq_pow=varargin{2};
end

%===
% Randomize bin ordering
%===

N_rand=randperm(length(triplet_freq));
triplet_freq=sqrt(triplet_freq(N_rand));
triplet_color=triplet_color(N_rand);

%===
% Reconstruct color triplets from col_val
% Sphere triplets
%===

triplet_color=([rem(triplet_color,256) floor(rem(triplet_color,256*256)/256) floor(triplet_color/(256*256))]/255);
triplet_color_norm=triplet_color./repmat(((sum(triplet_color.^(1),2))+.005),1,3);
max(triplet_color_norm)
triplet_diff=sum(abs(triplet_color_norm-repmat(triplet_color_norm(end,:),size(triplet_color_norm,1),1)),2);
triplet_diff=sum(abs(triplet_color_norm-repmat([.9 0 0],size(triplet_color_norm,1),1)),2);

max(triplet_diff)
triplet_diff=(triplet_diff/max(triplet_diff).^(color_pow))+(triplet_freq*0).^(freq_pow);



[d,inds_sort]=sort(triplet_diff);
triplet_freq=(triplet_freq(inds_sort));
triplet_color=(triplet_color(inds_sort,:));

num_bars=length(triplet_color);
max_val=max(triplet_freq);


figure(2);
axis([-.2 1.2 -.2 1.2]);
hold on;

num_total_freq=sum(triplet_freq);
disp(num_total_freq)

%===
% (Exp. A)
% The bins of triplet frequencies seem to follow a power law.
% Plotting a very large number for one triplet bin is unnecessary, so the
% number of points plotted for the maximally frequent triplet is set to 100
% and the median frequency is set to have about 45 points plotted
% (hence the number 45) in the equation below

%===
triplet_freq_normalizer=45/(median(unique(triplet_freq))*15);


for i=1:num_bars
    tempColor=triplet_color(i,:);
    dist_scatter=min((triplet_freq(i)*100/num_total_freq),.1);

    %===
    % see (Exp. A) aboce
    %===
    for j=1:min(ceil(triplet_freq(i)*15*triplet_freq_normalizer),100)

        %===
        % A scatter cloud is produced for each bin by assigning a radius to
        % each cloud that is proportional to the number of triplets in that
        % bin. Therefore, a color appearing frequently in the image will
        % have a larger scatter radius.
        %===
        r_dist=rand*dist_scatter;
        r_angle=rand*pi*2;
        x_val=sigmoidVal((tempColor(2)-tempColor(1)+1)*.5,8);
        %x_exp=.8+round(1-x_val);
        x_val=(x_val)+r_dist*cos(r_angle);
        y_val=(tempColor(3)+.1)/(tempColor(2)+tempColor(1)+tempColor(3)+.3);
        y_val=y_val+r_dist*sin(r_angle);

        plot(x_val,...
            y_val,...
            '.',...
            'markerfacecolor',min(tempColor,.9),...
            'markeredgecolor',min(tempColor,.9));
    end

end

set(gca,'xticklabel','')
set(gca,'yticklabel','')
set(gcf,'position',[573 380 560 420]);
axis equal;
axis tight;
axis([-.03 1.03 -.03 1.03]);
set(gca,'visible','off')


function y_val=sigmoidVal(x_val,varargin)

if nargin==1
    multip_val=15;
else
    multip_val=varargin{1};
end

y_val=1./(1+exp(-(x_val-.5)*multip_val));


Thanks.

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
nittoo Manju 23 Jan, 2009 01:50:04
rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com