Index in position 2 exceeds array bounds. Index must not exceed 1024.
1 次查看(过去 30 天)
显示 更早的评论
I am student writing my thesis and new to matlab ,i have posted the code below in which the particle image velocimetry was attempted to be done.
clear all;
clc;
close all;
imagea = imread('image1.tif');
imageb = imread('image2.tif');
[xmax, ymax]=size(imagea);
wsize = [64, 64];
w_width = wsize(1);
w_height = wsize(2);
xmin = w_width/2;
ymin = w_height/2;
xgrid = 200:w_width/2:864;
ygrid = 200:w_height/2:1696;
w_xcount = length(xgrid);
w_ycount = length(ygrid);
x_disp_max = w_width/2;
y_disp_max = w_height/2;
test_ima(w_width, w_height) = 0;
test_imb(w_width+2*x_disp_max, w_height+2*y_disp_max) =0;
dpx(w_xcount, w_ycount) = 0;
dpy(w_xcount, w_ycount) = 0;
xpeak1 = 0;
ypeak1 = 0;
for i=1:(w_xcount)
for j=1:(w_ycount)
max_correlation = 0;
test_xmin = xgrid(i)-w_width/2;
test_xmax = xgrid(i)+w_width/2;
test_ymin = ygrid(j)-w_height/2;
test_ymax = ygrid(j)+w_height/2;
x_disp = 0;
y_disp = 0;
test_ima = imagea(test_xmin:test_xmax, test_ymin:test_ymax);
test_imb = imageb((test_xmin-x_disp_max):(test_xmax+x_disp_max), (test_ymin-y_disp_max):(test_ymax+y_disp_max));
correlation = normxcorr2(test_ima, test_imb);
[xpeak, ypeak] = find(correlation==max(correlation(:)));
xpeak1 = test_xmin + xpeak - wsize(1)/2 - x_disp_max;
ypeak1 = test_ymin + ypeak - wsize(2)/2 - y_disp_max;
dpx(i,j) = xpeak1 - xgrid(i);
dpy(i,j) = ypeak1 - ygrid(j);
end
end
quiver(dpy, -dpx)
8 个评论
Walter Roberson
2023-1-18
The images are indexed pseudocolor not grayscale. But that does not affect the size, and it looks like the colormap is in increments of 1/256 so it should turn out to make no color difference
Image Analyst
2023-1-19
"i have taken a part of image1 and using this function i wanted to find the location of it in the image2" <= yes but in your comment below to me you said that is the reason why you did not use my code. Why the discrepancy? And like I said there, you did not have to use a part of the main image as a template -- you could use whatever image you wanted. You could synthesize it or read it in from a file or whatever you want.
回答(2 个)
Image Analyst
2023-1-18
I do exactly that in my attached demo.
2 个评论
Image Analyst
2023-1-18
Yes, I know. I thought you'd realize that the template image could be anything. You could read it from a file of course. I didn't want to attach two image files with the demo and I wanted to just use built-in image for the demo, so I took the template image from the main image. But of course you can use whatever template image you want -- it doesn't have to come from the main image. I'm attaching a newer demo where I explicitly spell that out.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!