Error using horzcat Dimensions of matrices being concatenated are not consistent.

1 Ansicht (letzte 30 Tage)
sir i dont know where exactly i m getting this error in my code. please help me sir
%%matching process
function num = match(image1,image2)
% Find SIFT keypoints for each image [im1, des1, loc1] = sift(image1); [im2, des2, loc2] = sift(image2);
% distRatio: Only keep matches in which the ratio of vector angles from the % nearest to second nearest neighbor is less than distRatio. distRatio = 0.6;
% For each descriptor in the first image, select its match to second image. des2t = des2'; % Precompute matrix transpose for i = 1 : size(des1,1) dotprods = des1(i,:) * des2t; % Computes vector of dot products [vals,indx] = sort(acos(dotprods)); % Take inverse cosine and sort results
% Check if nearest neighbor has angle less than distRatio times 2nd.
if (vals(1) < distRatio * vals(2))
match(i) = indx(1);
else
match(i) = 0;
end
end
% Create a new image showing the two images side by side. im3 = appendimages(image1,image2);
% Show a figure with lines joining the accepted matches. figure('Position', [100 100 size(im3,2) size(im3,1)]); colormap('gray'); imagesc(im3); hold on; cols1 = size(im1,2); for i = 1: size(des1,1) if (match(i) > 0) line([loc1(i,2) loc2(match(i),2)+cols1], ... [loc1(i,1) loc2(match(i),1)], 'Color', 'c'); end end hold off; num = sum(match > 0); fprintf('Found %d matches.\n', num);
%%sift process
% [image, descriptors, locs] = sift(imageFile) % % This function reads an image and returns its SIFT keypoints. % Input parameters: % imageFile: the file name for the image. % % Returned: % image: the image array in double format % descriptors: a K-by-128 matrix, where each row gives an invariant % descriptor for one of the K keypoints. The descriptor is a vector % of 128 values normalized to unit length. % locs: K-by-4 matrix, in which each row has the 4 values for a % keypoint location (row, column, scale, orientation). The % orientation is in the range [-PI, PI] radians. % % function [image, descriptors, locs] = sift(imagefile)
% Load image image = imagefile;
% If you have the Image Processing Toolbox, you can uncomment the following % lines to allow input of color images, which will be converted to grayscale.
[plane]=size(image);
if plane==3
image = rgb2gray(image);
end
[rows, cols] = size(image);
% Convert into PGM imagefile, readable by "keypoints" executable f = fopen('tmp.jpg', 'w'); if f == -1 error('Could not create file tmp.jpg.'); end fprintf(f, 'P5\n%d\n%d\n255\n', cols, rows); fwrite(f, image, 'uint8'); fclose(f);
% Call keypoints executable if isunix command = '!./sift '; else command = '!siftWin32 '; end command = [command ' <tmp.pgm >tmp.key']; eval(command);
% Open tmp.key and check its header g = fopen('tmp.key', 'r'); if g == -1 error('Could not open file tmp.key.'); end [header, count] = fscanf(g, '%d %d', [1 2]); if count ~= 2 error('Invalid keypoint file beginning.'); end num = header(1); len = header(2); if len ~= 128 error('Keypoint descriptor length invalid (should be 128).'); end
% Creates the two output matrices (use known size for efficiency) locs = double(zeros(num, 4)); descriptors = double(zeros(num, 128));
% Parse tmp.key for i = 1:num [vector, count] = fscanf(g, '%f %f %f %f', [1 4]); %row col scale ori if count ~= 4 error('Invalid keypoint file format'); end locs(i, :) = vector(1, :);
[descrip, count] = fscanf(g, '%d', [1 len]);
if (count ~= 128)
error('Invalid keypoint file value.');
end
% Normalize each input vector to unit length
descrip = descrip / sqrt(sum(descrip.^2));
descriptors(i, :) = descrip(1, :);
end
fclose(g);
%% appendimage % im = appendimages(image1, image2) % % Return a new image that appends the two images side-by-side.
function im3 = appendimages(image1, image2)
% Select the image with the fewest rows and fill in enough empty rows % to make it the same height as the other image. rows1 = size(image1,1); rows2 = size(image2,1);
if (rows1 < rows2) image1(rows2,1) = 0; else image2(rows1,1) = 0; end
% Now append both images side-by-side. im3 = [image1 image2];
%%showkeys % showkeys(image, locs) % % This function displays an image with SIFT keypoints overlayed. % Input parameters: % image: the file name for the image (grayscale) % locs: matrix in which each row gives a keypoint location (row, % column, scale, orientation)
function showkeys(image, locs)
disp('Drawing SIFT keypoints ...');
% Draw image with keypoints figure('Position', [50 50 size(image,2) size(image,1)]); colormap('gray'); imagesc(image); hold on; imsize = size(image); for i = 1: size(locs,1) % Draw an arrow, each line transformed according to keypoint parameters. TransformLine(imsize, locs(i,:), 0.0, 0.0, 1.0, 0.0); TransformLine(imsize, locs(i,:), 0.85, 0.1, 1.0, 0.0); TransformLine(imsize, locs(i,:), 0.85, -0.1, 1.0, 0.0); end hold off;
% ------ Subroutine: TransformLine ------- % Draw the given line in the image, but first translate, rotate, and % scale according to the keypoint parameters. % % Parameters: % Arrays: % imsize = [rows columns] of image % keypoint = [subpixel_row subpixel_column scale orientation] % % Scalars: % x1, y1; begining of vector % x2, y2; ending of vector function TransformLine(imsize, keypoint, x1, y1, x2, y2)
% The scaling of the unit length arrow is set to approximately the radius % of the region used to compute the keypoint descriptor. len = 6 * keypoint(3);
% Rotate the keypoints by 'ori' = keypoint(4) s = sin(keypoint(4)); c = cos(keypoint(4));
% Apply transform r1 = keypoint(1) - len * (c * y1 + s * x1); c1 = keypoint(2) + len * (- s * y1 + c * x1); r2 = keypoint(1) - len * (c * y2 + s * x2); c2 = keypoint(2) + len * (- s * y2 + c * x2);
line([c1 c2], [r1 r2], 'Color', 'c');
%%main program clc; close all; clear all; %h=imread('cameraman.tif'); [filename pathname]=uigetfile({'*.jpg;*.png;*.bmp'}); reff=imread([pathname filename]); reff=imresize(reff,[240 320]); figure,imshow(reff),title('Referrence image'); [filename, pathname]=uigetfile({'*.jpg;*.png;*.bmp'}); test=imread([pathname filename]); test=imresize(test,[240 320]); figure,imshow(test),title('Test image');
% preprocessing test=preprocessing(test); %% matching
%% num= match(reff,test);
sir please help me sir
  1 Kommentar
Stephen23
Stephen23 am 19 Apr. 2017
Bearbeitet: Stephen23 am 19 Apr. 2017
"where exactly i m getting this error"
The error message states where an error occurs. If you had uploaded the complete error message instead of that impossible-to-read code, then we would be able to start helping you.
If you want help, do both of these things:
  1. delete that unformatted code from the question, and upload it as a file (click the paperclip button).
  2. give the complete error message. This means all of the red text.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by