How to update the variable of a function using a dialogbox?
3 views (last 30 days)
Show older comments
INTRO: I use the script below to track the shift of a pixel between two images:
clear all; close all;
prompt = {'CORRELATION SIZE:'};
dlg_title = 'SHIFTED PIXEL';
def = {'5'};
answer = inputdlg(prompt,dlg_title,[1 20],def);
CORRSIZE = str2num(answer{1,1}); %#ok<ST2NM>
base_points_0 = [56 37];
input_points_0 = [56 37];
imagea = imread('1.bmp');
imageb = imread('2.bmp');
image1 = rgb2gray(imagea);
image2 = rgb2gray(imageb);
d = zeros(1,2,2);
d(:,:,1) = base_points_0;
[input_points, base_points] = cpselect(image2,image1, input_points_0, base_points_0,'Wait', true);
updated_inputs = cpcorr(input_points, base_points, image2, image1);
d(:,:,2) = updated_inputs;
The shift of a pixel between two images is correct if the variable CORRSIZE found in line 76 of cpcorr.m is chosen properly. Therefore, I begin the script with a dialo-gbox to allow to chose the CORRSIZE before the script runs.
PROBLEM: CORRSIZE is updated only in the workspace but not in the function cpcorr.m and consequently I always have to open cpcorr.m from the command line, go to line 76 and change it manually.
I wonder if someone could write me how could I update CPCORR from a dialog-box incorporated in the current script and thus avoid to open cpcorr.m and do all steps manually.
I thank you in advance for your help Emerson
0 Comments
Accepted Answer
Ahmed A. Selman
on 5 Apr 2013
Try the (while) loop with simple criterion, as:
clear all; close all;
prompt = {'CORRELATION SIZE:'};
dlg_title = 'SHIFTED PIXEL';
def = {'5'};
CORRSIZE = 5; % Here. Or any initial value, see below why
while (CORRSIZE); % Here.
answer = inputdlg(prompt,dlg_title,[1 20],def);
CORRSIZE = str2num(answer{1,1}); %#ok<ST2NM>
if CORRSIZE==0; % Here. When you input ZERO it will stop.
break % Here
end % Here. To end the endless loop
base_points_0 = [56 37];
input_points_0 = [56 37];
imagea = imread('1.bmp');
imageb = imread('2.bmp');
image1 = rgb2gray(imagea);
image2 = rgb2gray(imageb);
d = zeros(1,2,2);
d(:,:,1) = base_points_0;
[input_points, base_points] = cpselect(image2,image1, input_points_0, base_points_0,'Wait', true);
updated_inputs = cpcorr(input_points, base_points, image2, image1);
d(:,:,2) = updated_inputs;
end % Here. End of while loop
Please notice that I added the lines ending with ( %Here ). Perhaps it works now as required.
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!