Is there a technique to merge two peaks into one peak at the midpoint?
5 次查看(过去 30 天)
显示 更早的评论
Is it possible to merge two peaks into one through image processing methods or techniques such as matrix averaging or clustering?
What I want is to see a single peak in the middle of that location.
load('data.mat')
figure
subplot 121
imagesc(data);
subplot 122
surf(data);
An additional question is, can I use a CNN to detect the yellow areas and merge them together like I want?
0 个评论
采纳的回答
Mathieu NOE
2023-8-31
hello
maybe this ? (a low tech approach...)
load('data.mat')
[m,n] = size(data);
%% find the two peaks location
MinPeakH = 0.5*max(data,[],'all');
[pks,locs_y,locs_x]=peaks2(data,'MinPeakHeight',MinPeakH);
% isolate each peak by 2D gaussian filter
dx = diff(locs_x);
dy = diff(locs_y);
dd = sqrt(dx^2+dy^2);
%Gaussian filter
x = 1:n;
y = 1:m;
sigma = dd/2;
% first peak
x01 = locs_x(1);
y01 = locs_y(1);
[X,Y] = meshgrid(x,y);
g = exp(-((X-x01).^2+(Y-y01).^2)./(2*sigma^2));
data1 = data.*g;
% second peak
x02 = locs_x(2);
y02 = locs_y(2);
[X,Y] = meshgrid(x,y);
g = exp(-((X-x02).^2+(Y-y02).^2)./(2*sigma^2));
data2 = data.*g;
%% re-centering the data to the mid point
% mid point between two peaks
xm = round(mean(locs_x));
ym = round(mean(locs_y));
figure
subplot 131
imagesc(data); hold on
plot(locs_x,locs_y,'+r','markersize',25);
plot(xm,ym,'+k','markersize',25);
subplot 132
imagesc(data1);
subplot 133
imagesc(data2);
% shift peak1 data
sx = xm - x01; % x shift move
sy = ym - y01; % y shift move
data1s = ones(m,n)*min(data,[],'all');
data1s(1+sx:m,1+sy:n) = data1(1:m-sx,1:n-sy);
% shift peak2 data
sx = -xm + x02; % x shift move
sy = -ym + y02; % y shift move
data2s = ones(m,n)*min(data,[],'all');
data2s(1:m-sx,1:n-sy) = data2(1+sx:m,1+sy:n);
figure
subplot 131
imagesc(data); hold on
plot(locs_x,locs_y,'+r','markersize',25);
plot(xm,ym,'+k','markersize',25);
subplot 132
imagesc(data1s); hold on
plot(xm,ym,'+k','markersize',25);
subplot 133
imagesc(data2s); hold on
plot(xm,ym,'+k','markersize',25);
% mean of both shifted datas
datas = (data1s+data2s)/2;
figure
subplot 121
imagesc(data); hold on
plot(locs_x,locs_y,'+r','markersize',25);
plot(xm,ym,'+k','markersize',25);
subplot 122
imagesc(datas); hold on
plot(xm,ym,'+k','markersize',25);
0 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!