fourier image of angled shape, and changes when cropping
1 view (last 30 days)
Show older comments
Hi
Attached is an image (please unzip) which has some kind of spot in an angle.
I'm performing the following fft as in the photo and using regionprops.
Why if i use crop, imcrop, the angle of the ellipse changes in the fft? what am i doing wrong here? I assume I should scale somehow the fft before the use of the regionprops.
I0_original = imread('1.tiff')
I0 = medfilt2(I0_original);
I = (double(I0) - double(min(I0(:))))/double(max(I0(:)) - min(I0(:)));
B = imbinarize(I, 'global');
If = fftshift(fft2(I0)); %% fft and fftshift - into center highest power
If_abs=abs(If);
dB = 10*log10(If_abs); %% convert into dB scale
dB = (double(dB) - min(dB(:)))/double(max(dB(:)) - min(dB(:))); % standardization
B2 = imbinarize(dB, 'adaptive');
[~, xc, ~, ~, ang] = analysis(dB, B2, 'FFT (dB scale)');
function [Bf, xc, lmx, lmn, ang] = analysis(I, B, str)
prop = regionprops(B, 'Area', 'Centroid', 'MajorAxisLength', 'MinorAxisLength', 'Orientation', 'BoundingBox');
for i = 1:length(prop)
area(i) = prop(i).Area;
end
[~, idx] = max(area); % get region with maximum area
Bf = B;
for i = 1:length(prop) % remove regions with no maximum area
if i ~= idx
bx = round(prop(i).BoundingBox);
xs = max(1, bx(2));
xe = min(bx(2)+bx(4), size(I, 1));
ys = max(1, bx(1));
ye = min(bx(1)+bx(3), size(I, 2));
Bf(xs:xe, ys:ye) = 0; % removing
end
end
xc = round(prop(idx).Centroid); % centroid
lmx = prop(idx).MajorAxisLength; % major axis length
lmn = prop(idx).MinorAxisLength; % minor axis length
ang = prop(idx).Orientation; % orientation angle in deg
bx = prop(idx).BoundingBox; % bounding box
disp(['(', num2str(xc(1)), ', ', num2str(xc(2)), '), ',...
num2str(lmx), ', ', num2str(lmn), ', ', num2str(ang)])
end
0 Comments
Answers (2)
DGM
on 4 Jun 2021
Edited: DGM
on 4 Jun 2021
Because the results of fft2() are scaled to match the geometry of the image it operates on, the shape of objects in the fft image depends on the aspect ratio of the input image.
If you want them to remain the same, you could resize dB (or some intermediate image) to have the same geometry as the uncropped image, or you could at least adjust it to have the same aspect ratio.
There's probably some canonical way to manage this, but I never really work with freq domain tasks.
See Also
Categories
Find more on Image Segmentation and Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!