Align an image according to another.
2 views (last 30 days)
Show older comments
cindy asmat
on 27 Mar 2019
Answered: PRADEEPRAJ BALAKRISHNAN
on 22 Feb 2020
Hi,
I have been using the code that I include below to be able to align a group of images, but when I process the images, the image flipped over. Is there some way that MATLAB only choose points in the part where the staircase is?
Thank you.
Fixed: template_image1701F
Moving: 1701-12f
Result: 20170120192054
Code:
%Specify the folder.
path_name='D:\Data_Files\Westshore\Westshore Pics\2017\1701\F\';
file_name=dir([path_name,'input_images\*.JPG']);
%Choose a reference image
template_name='template_image1701F.jpg';
for j=19%1:length(file_name)
I=imread([path_name,'input_images\',file_name(j).name]);
fixed = rgb2gray(imread(template_name));
moving = rgb2gray(I);
fixedRefObj = imref2d(size(fixed));
movingRefObj = imref2d(size(moving));
fixedPoints = detectSURFFeatures(fixed);
movingPoints = detectSURFFeatures(moving);
[fixedFeatures,fixedValidPoints] = extractFeatures(fixed,fixedPoints);
[movingFeatures,movingValidPoints] = extractFeatures(moving,movingPoints);
indexPairs = matchFeatures(fixedFeatures,movingFeatures);
fixedMatchedPoints = fixedValidPoints(indexPairs(:,1));
movingMatchedPoints = movingValidPoints(indexPairs(:,2));
[tform, inlierDistorted, inlierOriginal] = estimateGeometricTransform(...
movingMatchedPoints,fixedMatchedPoints, 'similarity');
Rfixed = imref2d(size(fixed));
J = imwarp(I,tform,'FillValues', 255,'OutputView',Rfixed);
meta_data_im=imfinfo([path_name,'input_images\',file_name(j).name]);
name_save_file=[path_name,'output_images\',erase(erase(meta_data_im.DateTime,':'),' '),'.jpg'];
date_taken=meta_data_im.DateTime;
date_taken(5)='-';
date_taken(8)='-';
B =insertText(J,[1277 95],date_taken,'FontSize',40,'BoxColor','white','TextColor','black');
imwrite(B,name_save_file);
j
end
0 Comments
Accepted Answer
faheem ifti
on 11 May 2019
In the code line below....
J = imwarp(I,tform,'FillValues', 255,'OutputView',Rfixed);
Replace 'I' with the image required to be aligned (not the reference image). Tried it. Works
0 Comments
More Answers (2)
Image Analyst
on 27 Mar 2019
I haven't tried that way. If the shift is not too great, why not try the simpler imregister()?
0 Comments
PRADEEPRAJ BALAKRISHNAN
on 22 Feb 2020
function wave=ReadLeCroyBinaryWaveform(fn)
%---------------------------------------------------------------------------------------
% Open File
%---------------------------------------------------------------------------------------
fid=fopen('C1_u_lo_00993.trc');
if fid==-1
fprintf('ERROR: file not found: %s\n', fn);
return
end
%--------------------------------------------------------------------------------------- % Seek offset in the header block %--------------------------------------------------------------------------------------- data=fread(fid,50); WAVEDESC = strfind ('WAVEDESC', char(data()))-1; % subtract 1 because: % - 1st byte in the File = Index [0] % - 1st byte in the Matlab-Array = Index[1]
%--------------------------------------------------------------------------------------- % Define the addresses of the various informations in the file % These addresses are valid for the template LECROY_2_3 and are subject to change in % future revisions of the LeCroy firmware. Testing to this template version % has been disabled to facilitate decoding of waveforms from scopes % utilizing version 2_2 of the template. %--------------------------------------------------------------------------------------- TESTED_TEMPLATE = 'LECROY_2_3';
%Addresses (WAVEDESC + address as stated in the LECROY template) aTEMPLATE_NAME = WAVEDESC+ 16; aCOMM_TYPE = WAVEDESC+ 32; aCOMM_ORDER = WAVEDESC+ 34; aWAVE_DESCRIPTOR = WAVEDESC+ 36; % length of the descriptor block aUSER_TEXT = WAVEDESC+ 40; % length of the usertext block aTRIGTIME_ARRAY = WAVEDESC+ 48; aWAVE_ARRAY_1 = WAVEDESC+ 60; % length (in Byte) of the sample array aINSTRUMENT_NAME = WAVEDESC+ 76; aINSTRUMENT_NUMBER = WAVEDESC+ 92; aTRACE_LABEL = WAVEDESC+ 96; aWAVE_ARRAY_COUNT = WAVEDESC+ 116; aSUBARRAY_COUNT = WAVEDESC+ 144; aVERTICAL_GAIN = WAVEDESC+ 156; aVERTICAL_OFFSET = WAVEDESC+ 160; aNOMINAL_BITS = WAVEDESC+ 172; aHORIZ_INTERVAL = WAVEDESC+ 176; aHORIZ_OFFSET = WAVEDESC+ 180; aVERTUNIT = WAVEDESC+ 196; aHORUNIT = WAVEDESC+ 244; aTRIGGER_TIME = WAVEDESC+ 296; aRECORD_TYPE = WAVEDESC+ 316; aPROCESSING_DONE = WAVEDESC+ 318; aTIMEBASE = WAVEDESC+ 324; aVERT_COUPLING = WAVEDESC+ 326; aPROBE_ATT = WAVEDESC+ 328; aFIXED_VERT_GAIN = WAVEDESC+ 332; aBANDWIDTH_LIMIT = WAVEDESC+ 334; aVERTICAL_VERNIER = WAVEDESC+ 336; aACQ_VERT_OFFSET = WAVEDESC+ 340; aWAVE_SOURCE = WAVEDESC+ 344;
%--------------------------------------------------------------------------------------- % determine the number storage format HIFIRST / LOFIRST (big endian / little endian) %---------------------------------------------------------------------------------------
fseek(fid,50,'bof'); COMM_ORDER=fread(fid,1,'int16');
fclose(fid); % reopen the data file using the correct HIFIRST/LOFIRST format if COMM_ORDER==0 fid=fopen('C1_u_lo_00993.trc'); % HIFIRST else fid=fopen('C1_u_lo_00993.trc'); % LOFIRST end
%--------------------------------------------------------------------------------------- % Get the waveform information %--------------------------------------------------------------------------------------- % Check the template revision (Commented out to facilitate decoding of 2_2 % files TEMPLATE_NAME = ReadString(fid, aTEMPLATE_NAME); if ~strcmp( deblank(TEMPLATE_NAME), TESTED_TEMPLATE) fprintf ('WARNING!\n %s %s %s\n %s %s %s\n',... 'This function has been written for the LeCroy-Template',... TESTED_TEMPLATE, '.',... 'The current file contains information created with the template',... TEMPLATE_NAME, '.'); end
% Instrument wave.info.INSTRUMENT_NAME = ReadString(fid, aINSTRUMENT_NAME); wave.info.INSTRUMENT_NUMBER = ReadLong (fid, aINSTRUMENT_NUMBER); wave.info.Filename = fn;
% Channel wave.info.TRIGGER_TIME = ReadTimestamp(fid, aTRIGGER_TIME);
tmp=['channel 1';'channel 2';'channel 3';'channel 4';'unknown ']; wave.info.WAVE_SOURCE = tmp (1+ ReadWord(fid, aWAVE_SOURCE),:);
tmp=['DC_50_Ohms'; 'ground ';'DC 1MOhm ';'ground ';'AC 1MOhm ']; wave.info.VERT_COUPLING = deblank (tmp (1+ ReadWord(fid, aVERT_COUPLING),:));
tmp=['off'; 'on ']; wave.info.BANDWIDTH_LIMIT = deblank (tmp (1+ ReadWord(fid, aBANDWIDTH_LIMIT),:));
tmp=[ 'single_sweep '; 'interleaved '; 'histogram '; 'graph '; 'filter_coefficient'; 'complex '; 'extrema '; 'sequence_obsolete '; 'centered_RIS '; 'peak_detect ']; wave.info.RECORD_TYPE = deblank (tmp (1+ ReadWord(fid, aRECORD_TYPE),:));
tmp=[ 'no_processing'; 'fir_filter '; 'interpolated '; 'sparsed '; 'autoscaled '; 'no_result '; 'rolling '; 'cumulative ']; wave.info.PROCESSING_DONE = deblank (tmp (1+ ReadWord(fid, aPROCESSING_DONE),:));
% Vertical settings FIXED_VERT_GAIN = ReadFixed_vert_gain(fid, aFIXED_VERT_GAIN); PROBE_ATT = ReadFloat (fid, aPROBE_ATT); VERTICAL_GAIN = ReadFloat (fid, aVERTICAL_GAIN); VERTICAL_OFFSET = ReadFloat (fid, aVERTICAL_OFFSET); wave.info.NOMINAL_BITS = ReadWord (fid, aNOMINAL_BITS); wave.info.Gain_with_Probe = strcat (Float_to_Eng(FIXED_VERT_GAIN*PROBE_ATT), 'V/div');
% Horizontal settings HORIZ_INTERVAL = ReadFloat(fid, aHORIZ_INTERVAL); HORIZ_OFFSET = ReadDouble(fid, aHORIZ_OFFSET); wave.info.TIMEBASE = strcat (Float_to_Eng (ReadTimebase(fid,aTIMEBASE)), 's/div'); wave.info.SampleRate = strcat (Float_to_Eng(1/HORIZ_INTERVAL) , 'S/sec'); wave.desc.Ts = HORIZ_INTERVAL; wave.desc.fs = 1/HORIZ_INTERVAL;
%--------------------------------------------------------------------------------------- % Read samples array (Plain binary ADC values) %--------------------------------------------------------------------------------------- COMM_TYPE = ReadWord(fid, aCOMM_TYPE); WAVE_DESCRIPTOR = ReadLong(fid, aWAVE_DESCRIPTOR); USER_TEXT = ReadLong(fid, aUSER_TEXT); WAVE_ARRAY_1 = ReadLong(fid, aWAVE_ARRAY_1); WAVE_ARRAY_COUNT = ReadLong(fid, aWAVE_ARRAY_COUNT); TRIGTIME_ARRAY = ReadLong(fid, aTRIGTIME_ARRAY);
% returns number of segments in acquisition wave.info.nbSegments = ReadLong(fid, aSUBARRAY_COUNT);
if wave.info.nbSegments > 1 % for sequence mode only
%---------------------------------------------------------------------------------------
% Read contents of TRIGTIME_ARRAY, which is an interleaved array
%---------------------------------------------------------------------------------------
% Take from X-Stream oscilloscopes remote control manual, appendix II:
% < 0> TRIGGER_TIME: double ; for sequence acquisitions,
% ; time in seconds from first
% ; trigger to this one
% < 8> TRIGGER_OFFSET: double ; the trigger offset is in seconds
% ; from trigger to zeroth data point
fseek(fid, WAVEDESC + WAVE_DESCRIPTOR + USER_TEXT, 'bof');
trigtime_array_temp = fread(fid, 2*wave.info.nbSegments, 'double');
% We need to de-interleave the trigger_time and trigger_offset data.
wave.trigger_time = trigtime_array_temp(1:2:end);
wave.trigger_offset = trigtime_array_temp(2:2:end);
if WAVE_ARRAY_1/wave.info.nbSegments ~= WAVE_ARRAY_1/wave.info.nbSegments
% if this condition happens, MATLAB will pad the rest of the output
% matrix with zeros, so the file is still readable, but this could
% signify another error (in this m-file?)
warning('While reading segment file: Total number of points is not a multiple of the number of segments');
end
%---------------------------------------------------------------------------------------
% Read the ADC values into a matrix
%---------------------------------------------------------------------------------------
% since this is a sequence acquisition, we will return a
% (WAVE_ARRAY_COUNT/nbSegments)x(nbSegments) matrix, where each column is one segment.
fseek(fid, WAVEDESC + WAVE_DESCRIPTOR + USER_TEXT + TRIGTIME_ARRAY, 'bof');
if COMM_TYPE == 0 % byte
wave.y = fread(fid, [WAVE_ARRAY_COUNT/wave.info.nbSegments wave.info.nbSegments], 'int8');
else % word
wave.y = fread(fid, [WAVE_ARRAY_COUNT/wave.info.nbSegments wave.info.nbSegments], 'int16');
end
%---------------------------------------------------------------------------------------
% Create corresponding matrix of time, with correction for each trigger time
%---------------------------------------------------------------------------------------
wave.x = repmat(wave.trigger_time.', WAVE_ARRAY_COUNT/wave.info.nbSegments, 1) + repmat((0:WAVE_ARRAY_COUNT/wave.info.nbSegments-1)'*HORIZ_INTERVAL + HORIZ_OFFSET, 1, wave.info.nbSegments);
else
fseek(fid, WAVEDESC + WAVE_DESCRIPTOR + USER_TEXT + TRIGTIME_ARRAY, 'bof');
if COMM_TYPE == 0 % byte
wave.y=fread(fid,WAVE_ARRAY_1, 'int8');
else % word
wave.y=fread(fid,WAVE_ARRAY_1, 'int16');
end
%---------------------------------------------------------------------------------------
% Create corresponding array of time
%---------------------------------------------------------------------------------------
wave.x = (0:WAVE_ARRAY_COUNT-1)'*HORIZ_INTERVAL + HORIZ_OFFSET;
end
%--------------------------------------------------------------------------------------- % Transform the ADC values to voltages %--------------------------------------------------------------------------------------- wave.y = VERTICAL_GAIN * wave.y - VERTICAL_OFFSET;
%--------------------------------------------------------------------------------------- % close the waveform file %--------------------------------------------------------------------------------------- fclose(fid); end
I need a graph as an output can anyone help me please to sort out this.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!