I want to reconstruct an image of circles with noise

2 visualizaciones (últimos 30 días)
Hoschang Noori
Hoschang Noori el 18 de Jul. de 2020
Comentada: Image Analyst el 24 de Jul. de 2020
Hello,
i want to reconstruct a similar image of the following one from a plot.
You can find this image attached as 'copy.txt'.
This is the plot i have
What steps should i take? I have to thicken the lines of the circle-lines and give them different values. The ones presented should have high values and it should fade away.
What i have:
%Used values from now on.
savedValsX;
savedValsY;
%Size Image: 1043x981
%Size Simu Plot: detHeight = 179.4 mm, detWidth = 168.7 mm
%convert mm to pixels
imHeight = 1043;
imWidth = 981;
mmToPixFactor = round(imHeight/detHeight, 2)
%save values as pixels.
savedValsX = savedValsX.*mmToPixFactor - min(savedValsX.*mmToPixFactor);
savedValsY = savedValsY.*mmToPixFactor - min(savedValsY.*mmToPixFactor);
% Setup / initialization.
% Start out matrix as zeros.
m = zeros(1050,1000);
%Save x, y locations as int32, transpose everything.
savedValsX = floor(savedValsX)
savedValsY = floor(savedValsY)
valsX = savedValsX.';
valsY = savedValsY.';
%Delete Zero elements.
zeroX = find(valsX == 0);
zeroY = find(valsY == 0);
maxX = find(valsX > 981)
valsX(zeroX) = 1;
valsY(zeroY) = 1;
plot(valsX, valsY, "r*")
XY = [valsX, valsY];
z = 1;
indexes = sub2ind([1050, 1000], XY(:,2), XY(:,1));
m(indexes) = z;
m = flip(m,1)
Anyone know what keyword i should look after or did anyone do something familiar to this? Making an image of out a plot?
Thanks in advance!
This is the full code that i use to get the x and y values. You can find the used xy values attached as a txt.
%% define some colors and symbols for plotting
symbols = {'s','^','p','d','v','o','+','x','*','h','<','>','.','s','^','p',...
'd','v','o','+','x','*','h','<','>','.','s','^','p','d','v','o','+','x',...
'*','h','<','>','.','s','^','p','d','v','o','+','x','*','h','<','>','.'};
colors = {'r','g','b','c','m','y','r','g','b','c','m','y','r','g','b','c',...
'm','y','r','g','b','c','m','y','r','g','b','c','m','y','r','g','b','c',...
'm','y','r','g','b','c','m','y','r','g','b','c','m','y','r','g','b','c'};
lineTypes = {'-','--',':','-.'};
%% Simulation of area detector images (powder samples, position is linked to the detector center)
angleVals = 0:360;
roiX = 1000; % mm (region of interest of diffraction image, horizontal), for In radiation
roiY = 1000; % mm (region of interest of diffraction image, vertical), for In radiation
detHeight = 179.4; % mm, DECTRIS PILATUS 1M
detWidth = 168.7; % mm, DECTRIS PILATUS 1M
detPosX = 300; % mm (perpendicular horizontal to the specimen)
detPosY = 90; % mm (perpendicular vertical to the specimen)
detPosZ = 500; % mm (in the direction of specimen), for In radiation
type = 'bcc';
maxPeakArea = 1000;
peakWidth = 0.4;
wavelengthTexts = {'In-Ka1'};
usedWavelengths = [0.051212641];
% wavelengthTexts = {'Ga-Ka1'};
% usedWavelengths = [0.134011837];
xSteps = 5; % In radiation
xMax = 80; % In radiation
% define lattice and material parameters
hklBcc = [110, 200, 211, 220, 310, 222, 321, 400, 330, 420, 332, 422, 431, 521, 440, 530, ...
442, 611, 620, 541, 622]';
a0ValFerrit = 0.28665;
% select correct values for lattice planes and lattice parameter
hklVals = hklBcc;
a0Val = a0ValFerrit;
% determine lattice spacings of selected material
l = mod(hklVals, 10);
k = mod(floor(hklVals./10), 10);
h = floor(hklVals./100);
dVals = a0Val ./ (h.^2 + k.^2 + l.^2).^0.5;
hklInt = [h, k, l, ones(size(hklVals))];
% determine diffraction angles and diffraction radius values
angles = 2 .* asind(usedWavelengths ./ (2 .* dVals));
useful = find(imag(angles) == 0);
curHklVals = hklVals(useful);
hklUsed = curHklVals;
curAngles = angles(useful);
tthUsed = curAngles;
curRadius = detPosZ*tand(tthUsed);
radiusUsed = curRadius;
% determine spectrum
peakValsX = 0:0.1:curAngles(end) + 5;
peakData = zeros(length(curHklVals), length(peakValsX));
peakIntVals = zeros(size(curHklVals));
% determine diffraction rings
xVals = zeros(length(curRadius), length(angleVals));
yVals = zeros(length(curRadius), length(angleVals));
relValsDetCur = zeros(length(curRadius), length(angleVals));
for j = 1:length(curRadius)
xValsCur = curRadius(j) * cosd(angleVals);
yValsCur = curRadius(j) * sind(angleVals);
xVals(j,:) = xValsCur;
yVals(j,:) = yValsCur;
end
diffRingsX = xVals;
diffRingsY = yVals;
figure
hold on
curRadius = radiusUsed;
savedValsX = [];
savedValsY = [];
for j = 1:size(diffRingsX, 1)
if curRadius(j) > 0
curValsX = diffRingsX(j,:);
curValsY = diffRingsY(j,:);
relValsDetCur = curValsX >= detPosX - detWidth/2 & curValsX <= detPosX + detWidth/2 & ...
curValsY >= detPosY - detHeight/2 & curValsY <= detPosY + detHeight/2;
savedValsX = [savedValsX curValsX(relValsDetCur)];
savedValsY = [savedValsY, curValsY(relValsDetCur)];
plot(curValsX(relValsDetCur), curValsY(relValsDetCur), [colors{1} '*'])
end
end
hold off
xlim([detPosX - detWidth/2, detPosX + detWidth/2])
ylim([detPosY - detHeight/2, detPosY + detHeight/2])
grid
title(['Detector: ' num2str(detPosX) ', ' num2str(detPosY) ', ' num2str(detPosZ) ', ' ...
num2str(detWidth) ', ' num2str(detHeight) ', a_0=' num2str(a0Val) 'nm, ' type])
%Used values from now on.
savedValsX; savedValsY;
%Size Image: 1043x981
%Size Simu Plot: detHeight = 179.4 mm, detWidth = 168.7 mm
%convert mm to pixels
imHeight = 1043;
imWidth = 981;
mmToPixFactor = round(imHeight/detHeight, 2)
%save values as pixels.
savedValsX = savedValsX.*mmToPixFactor - min(savedValsX.*mmToPixFactor);
savedValsY = savedValsY.*mmToPixFactor - min(savedValsY.*mmToPixFactor);
% Setup / initialization.
% Start out matrix as zeros.
m = zeros(1050,1000);
%Save x, y locations as int32, transpose everything.
savedValsX = floor(savedValsX)
savedValsY = floor(savedValsY)
valsX = savedValsX.';
valsY = savedValsY.';
%Delete Zero elements.
zeroX = find(valsX == 0);
zeroY = find(valsY == 0);
maxX = find(valsX > 981)
valsX(zeroX) = 1;
valsY(zeroY) = 1;
plot(valsX, valsY, "r*")
XY = [valsX, valsY];
max(valsX)
max(valsY)
z = 1;
indexes = sub2ind([1050, 1000], XY(:,2), XY(:,1));
m(indexes) = z;
m = flip(m,1)
mImage = imagesc(m)
colorbar

Respuestas (1)

Image Analyst
Image Analyst el 18 de Jul. de 2020
Maybe you want to use scatteredInterpolant(), like my attached demo. It takes x, y, value coordinates and builds up an image. You should make sure you "pin down" the borders of your image with some value, like the min of your other values, so it doesn't go crazy there.
  4 comentarios
Hoschang Noori
Hoschang Noori el 24 de Jul. de 2020
Editada: Hoschang Noori el 24 de Jul. de 2020
The third scenario sounds good. What I try is to generate a similiar image/matrix to this (without noise) from the plot.
Thanks a lot for your help!
Image Analyst
Image Analyst el 24 de Jul. de 2020
If you have a list of (x,y) locations, then here is how to burn it into the image:
for k = 1 : length(x)
row = round(y(k));
column = round(x(k));
grayImage(row, columns) = 255; % Or 1 or whatever value you want.
end

Iniciar sesión para comentar.

Categorías

Más información sobre Lighting, Transparency, and Shading en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by