Artifacts appear on my matlab image
Show older comments
Hello everyone,
I wrote a matlab program to process my data, the results and in the form of image of different colors. The color scale is a choice and this is the problem, because when I use a colormap with 3 different colors I don't have this artifact that appears but when I use the one with the rainbow colors the artifact appears. I'm attaching the image and the code snippet for the colormap. Do you have any idea why I'm having this problem? How can I fix it?



1 Comment
Cris LaPierre
on 20 Aug 2024
Edited: Cris LaPierre
on 20 Aug 2024
k = [0 0 0]; %# start
p = [1 0 1];
n = [0 0 1];
b = [0 1 1];
g = [0 1 0]; %# middle
y = [1 1 0];
r = [1 0 0];
z = [0 0 0];%# end
% Colormap de taille 64x3, dégradée en arc-en-ciel
cl = zeros (32,3); c2 = zeros (32,3); c3 = zeros (32,3); c4 = zeros (32,3);
c5 = zeros (32,3); c6 = zeros (32,3); c7 = zeros (32,3);
for i = 1:3
cl(:,i) = linspace (k(i), p(i), 32);
c2(:,i) = linspace (p(i), n(i), 32);
c3(:,i) = linspace (n(i), b(i), 32);
c4(:,i) = linspace (b(i), g(i), 32);
c5(:,i) = linspace (g(i), y(i), 32);
c6(:,i) = linspace (y(i), r(i), 32);
c7(:,i) = linspace (r(i), z(i), 32);
end
% Combinaison de toutes les parties sans doublons
c = [cl(1:end-1,:); c2(1:end-1,:); c3(1:end-1,:); c4(1:end-1,:); c5(1:end-1,:); c6(1:end-1,:); c7];
% Afficher la surface
surf (peaks), shading interp
caxis([-1 1])
colormap(c)
colorbar
Answers (1)
Cris LaPierre
on 20 Aug 2024
0 votes
We'd have to see your code for 3 colors to say for certain, but here, your colormap sets anything above or below abs(1) to [0 0 0], or black. We don't have your processed data, but it would appear the region of the artifact must contain absolute values >= 1.
14 Comments
Tina
on 20 Aug 2024
Edited: Walter Roberson
on 20 Aug 2024
Cris LaPierre
on 20 Aug 2024
Edited: Cris LaPierre
on 20 Aug 2024
The difference is in your colormap. In the 7 color example (the one with the artifact), your colormap starts and ends with black. In your 3 color example, the colormap starts with blue and ends with red. If you do not want black in the extremes of your colormap, you must not include it when building your colormap variable.
In order for us to play around with your example, please share your processed data. You can save your variable(s) to a mat file and then attach it to your post using the paperclip icon.
Tina
on 20 Aug 2024
Tina
on 20 Aug 2024
Cris LaPierre
on 20 Aug 2024
The code you have shared does not create the figure you are showing. Please share all the relevant code so that we can duplicate the issue.
Tina
on 20 Aug 2024
The only code that creates a figure in the code you have shared is surf(peaks). However, that does not create your image.
surf(peaks)
Here is my best guess at what you may be doing. Note that it does not show the artifact. The code you have not shared must be doing something additional to the data that is causing the artifact to appear.
load V.mat
surf(X,Y,V1,'LineStyle','none')
view(2)
%----------------------------------------------------------------------------------bleu-blanc-rouge----------------------------
B = [0.0840 0.1747 0.3910]; %# start
b = [0 0 1];
g=[0.8290,0.8940, 0.0250]; %# middle
r = [1 0 0];
R = [0.6350 0.0780 0.1840]; %# end
%colormap of size 64-by-3
c1 = zeros(32,3); c2 = zeros(32,3);c3 = zeros(32,3);c4 = zeros(32,3);
for i=1:3
c1(:,i) = linspace(B(i), b(i), 32);
c2(:,i) = linspace(b(i), g(i), 32);
c3(:,i) = linspace(g(i), r(i), 32);
c4(:,i) = linspace(r(i), R(i), 32);
end
c = [c1(1:end-1,:);c2;c3;c4];
% surf(peaks),
shading interp
caxis([-1 1])
colormap(c)
colorbar
%----------------
figure
surf(X,Y,V1,'LineStyle','none')
view(2)
k = [0 0 0]; %# start
p = [1 0 1];
n = [0 0 1];
b = [0 1 1];
g = [0 1 0]; %# middle
y = [1 1 0];
r = [1 0 0];
z = [0 0 0];%# end
% Colormap de taille 64x3, dégradée en arc-en-ciel
cl = zeros (32,3); c2 = zeros (32,3); c3 = zeros (32,3); c4 = zeros (32,3);
c5 = zeros (32,3); c6 = zeros (32,3); c7 = zeros (32,3);
for i = 1:3
cl(:,i) = linspace (k(i), p(i), 32);
c2(:,i) = linspace (p(i), n(i), 32);
c3(:,i) = linspace (n(i), b(i), 32);
c4(:,i) = linspace (b(i), g(i), 32);
c5(:,i) = linspace (g(i), y(i), 32);
c6(:,i) = linspace (y(i), r(i), 32);
c7(:,i) = linspace (r(i), z(i), 32);
end
% Combinaison de toutes les parties sans doublons
c = [cl(1:end-1,:); c2(1:end-1,:); c3(1:end-1,:); c4(1:end-1,:); c5(1:end-1,:); c6(1:end-1,:); c7];
% Afficher la surface
caxis([-1 1])
colormap(c)
colorbar
Cris LaPierre
on 21 Aug 2024
Edited: Cris LaPierre
on 21 Aug 2024
I've edited your post so that the code can be run here. This does not generate the figure you are asking about. Could you share a working example that recreates the issue? Use the green play button in the toolstrip to run your code here.
Tina
on 21 Aug 2024
Cris LaPierre
on 21 Aug 2024
Great to hear. I've edited your post so that your code runs here as well, showing no artifact.
Tina
on 23 Aug 2024
Categories
Find more on Color and Styling 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!








