Powered by Blogger.

Archive for March 2013

Resizing multiple images using MATLAB




Get all the image files that are need to be re sized in matlab current directory and run this code


dirData = dir('*.jpg'); 
fileNames = {dirData.name};     
for iFile = 1:numel(fileNames)  
newName = sprintf('%1d.jpg',iFile); 
movefile(fileNames{iFile},newName);        
end  


After renaming the files (by running above program ) run this code

q=1;
p=1;
for i=1:10
oq=imread(strcat(num2str(q),'.jpg'));
odprz=imresize(oq,[150 150]);  %# specify your size here
imwrite(odprz,strcat(num2str(p),'.png'));
q=q+1;
p=p+1;
end 


collect only .png format files.That files are re-sized  files.


Automated image comparison using MATLAB


Automated image comparison using MATLAB







MAIN MOTIVE

This project presents the new machine learning process on images. In competitive intelligence information comparison the text analytic decides the product match type to enhance that automation process image comparison of the products is automated and presented here. Here the corner detection and comparison on images is used to compare the images.

USE CASES
            Mainly developed for competitive intelligence (i.e.) to compare online marketing client and competitor images.

Considerations
To compare images in large amount if we download images and compare the space needed will be more to overcome that scenario the image URLs are used from both client and competitor side. Images can be of any format in the case of comparison of images from URLs.
If input is image URLs mean that should be in excel file and output status of images equal or not equal will be stored in the specified column of excel sheet.
If images are stored in drives mean other process like renaming of images will be followed to get the images into the code execution. (Pre-processing is needed)

 PROCESS FLOW

Example images processed



COMPARISON DURING EXECUTION





 OUTPUT

         output will be stored in excel sheet.

status 1: equal

status 2: not equal


*********************************************************************************



q=2; %% source image name ('2.jpg')
    w=2;  %% another image ('2.png')
    sd=1;
for i=1:1
hIdtc = video.ImageDataTypeConverter();
hCsc = video.ColorSpaceConverter('Conversion','RGB to intensity');

oq=imread(strcat(num2str(q),'.jpg'));
odprz=imresize(oq,[150 150]);
imwrite(odprz,'oq1.jpg');


leftI3chan = step(hIdtc,imread('oq1.jpg'));
leftI = step(hCsc,leftI3chan);
disp(leftI)
sw=imread(strcat(num2str(w),'.png'));
stprz=imresize(sw,[150 150]);
imwrite(stprz,'sw1.png');

rightI3chan = step(hIdtc,imread('sw1.png'));
rightI = step(hCsc,rightI3chan);

harris = video.CornerDetector( 'MaximumCornerCount', 1000, ...
                               'CornerThreshold', 1e-4, ...
                               'NeighborhoodSize', [9 9] );
pointsLeft = flipud(step(harris, leftI))+1;
pointsRight = flipud(step(harris, rightI))+1;
% Trim point lists to minimum size.
pointsLeft = pointsLeft(:, 1:find(all(pointsLeft==1,1),1) - 1);
pointsRight = pointsRight(:, 1:find(all(pointsRight==1,1),1) - 1);
halfBlockSize = 4; % Block half-size.
blockSize = 2*halfBlockSize+1; % Full block size.
[r,c] = size(leftI);
matchThreshold = 0.7;

% Extract features for pointsRight
features = zeros(blockSize^2,size(pointsRight,2), 'single');
for i=1:size(pointsRight,2)
    T = zeros(blockSize, 'single');
    minr = max(1,pointsRight(2,i)-halfBlockSize);
    maxr = min(r,pointsRight(2,i)+halfBlockSize);
    minc = max(1,pointsRight(1,i)-halfBlockSize);
    maxc = min(c,pointsRight(1,i)+halfBlockSize);
    T( halfBlockSize+1-(pointsRight(2,i)-minr):halfBlockSize+1+(maxr-pointsRight(2,i)), ...
       halfBlockSize+1-(pointsRight(1,i)-minc):halfBlockSize+1+(maxc-pointsRight(1,i)) ) = ...
       rightI( minr:maxr, minc:maxc );
    features(:,i) = T(:);
end

% Loop over pointsLeft, looking for best matches in pointsRight via features.
ix1 = zeros(1,size(pointsLeft,2), 'single');
d = zeros(size(ix1), 'single');
for i=1:size(pointsLeft,2)
    T = zeros(blockSize, 'single');
    minr = max(1,pointsLeft(2,i)-halfBlockSize);
    maxr = min(r,pointsLeft(2,i)+halfBlockSize);
    minc = max(1,pointsLeft(1,i)-halfBlockSize);
    maxc = min(c,pointsLeft(1,i)+halfBlockSize);
    T( halfBlockSize+1-(pointsLeft(2,i)-minr):halfBlockSize+1+(maxr-pointsLeft(2,i)), ...
       halfBlockSize+1-(pointsLeft(1,i)-minc):halfBlockSize+1+(maxc-pointsLeft(1,i)) ) = ...
       leftI( minr:maxr, minc:maxc );
    % Find matching point in pointsRight with features features.
    [v,ix] = min( sum(bsxfun(@minus,features,T(:)).^2,1) );
    if v < matchThreshold
        ix1(i) = ix;
    end
end

% Extract indices of matched points on each side.
ix2 = nonzeros(ix1);
ix1 = find(ix1);
% Create subselected, homogenized point lists.
pointsLeftH  = [double(pointsLeft(:,ix1));  ones(1,length(ix1), 'single')];
pointsRightH = [double(pointsRight(:,ix2)); ones(1,length(ix2), 'single')];

figure(1), clf;
imshow(cat(3,rightI,leftI,leftI)), hold on;
plot(pointsLeftH(1,:),pointsLeftH(2,:),'x','Color',[0 0 1],'MarkerSize',8);
plot(pointsRightH(1,:),pointsRightH(2,:),'x','Color',[1 1 0],'MarkerSize',8);
plot([pointsLeftH(1,:);pointsRightH(1,:)],...
     [pointsLeftH(2,:);pointsRightH(2,:)],'-','Color',[0 1 0]);
set(gca,'XTick',[],'YTick',[]);
title('Initial corresponded points between the two images');

d1=mean(pointsRightH);
d2=mean(pointsRightH);
t1=mode(d2);
t2=mode(d1);


if t1 == t2  %% modify here put one extra  loop if t1<5 means result will be not a match(for better comparison)
result={'exact'};
disp(result)
else
result={'not found'};
disp(result)
end

xlswrite('myfile.xls',result,'sheet1',strcat('A',num2str(sd))) %%  excel file to store result

q=q+1;
w=w+1;
sd=sd+1;
end

 



********************************** THANK YOU***********************************


 Your valid suggestions  are anticipated to enhance the program.

LINKED IN :   in.linkedin.com/in/srimukunthan 


GMAIL : srimukunthan@gmail.com


FACEBOOK: www.facebook.com/mukunthan.gj


















                                                                                                                                                                     



- Copyright © Get Codes - Powered by Blogger - Designed by Mukunthan GJ -