As shown in the figure, when I set the linewidth for these subgraphs border
set(gca,'linewidth',1.5)
The linewidth of the lines in the red circle is not consistent
The original code is as follows
clc;clear
nlon = [100:140];
nlat = [20:60];
data = ones(length(nlon),length(nlat));
figure
for k =1:4
subplot(2,2,k)
p=pcolor(nlon,nlat,data');hold on
set(p,'linestyle','none');
fun_fill_AA; % **mask**
axis equal
axis([110 135 30 55])
set(gca,'linewidth',1.5)
end
function fun_fill_AA()
data0=[50 10
140 10
140 60
50 60]
data_lon=data0(:,1);
data_lat=data0(:,2);
fil=fill(data_lon,data_lat,[1 1 1]);
hold on
fil=fill(data_lon,data_lat,[1 1 1]);
fil.EdgeColor='none';
end
How can I make the borders of each subgraph have the same linewidth?
It's better after saving the image to higher resolutions.
left:
saves(gcf,'*.png')
right:
print(gcf,'*.png','-dpng','-r600');%*//600 dpi
How can I determine the intensity or ranging the darkness of a color based on probability distribution?
For instance in this code example
pgon1 = [-0.5 -0.6882; 0.5 -0.6882; 0.5 -1.6882;-0.5 -1.6882];
pgon2 = [0.5 -0.6882; 0.806 0.2629; 1.7571 -0.0431;1.4511 -0.9972];
pgon3 = [0.806 0.2629; 0 0.8507; 0.5878 1.6567;1.3938 1.0689];
pgon4 = [0 0.8507; -0.809 0.2629; -1.3968 1.1136;-0.5878 1.6597];
pgon5 = [ -0.809 0.2629; -0.5 -0.6882; -1.4511 -0.9972;-1.7601 -0.0461];
patch(pgon1(:,1),pgon1(:,2),ones(length(pgon1),1),'r')
patch(pgon2(:,1),pgon2(:,2),ones(length(pgon2),1)*2,'k')
patch(pgon3(:,1),pgon3(:,2),ones(length(pgon3),1)*3,'g')
patch(pgon4(:,1),pgon4(:,2),ones(length(pgon4),1)*4,'b')
patch(pgon5(:,1),pgon5(:,2),ones(length(pgon5),1)*5,'m')
axis equal tight
view(3)
grid on
Can the intensity of black or blue be a function of some probability between zero and one?
There are two alternatives:
It can be done using 'FaceColor' Property of the Patch object, with multiplying the RGB Triplet by some intensity value (according to your probabilities) , then you can adjust the darkness of a certain color:
patch(pgon1(:,1),pgon1(:,2),ones(length(pgon1),1)*1,'b','facecolor',0.20*[0, 0 1])
patch(pgon2(:,1),pgon2(:,2),ones(length(pgon2),1)*2,'b','facecolor',0.30*[0, 0 1])
patch(pgon3(:,1),pgon3(:,2),ones(length(pgon3),1)*3,'b','facecolor',0.50*[0, 0 1])
patch(pgon4(:,1),pgon4(:,2),ones(length(pgon4),1)*4,'b','facecolor',0.75*[0, 0 1])
patch(pgon5(:,1),pgon5(:,2),ones(length(pgon5),1)*5,'b','facecolor',1 *[0, 0 1])
OR
By using the 'FaceAlpha' Property, you can adjust the transparency of a certain color according to your probability:
patch(pgon1(:,1),pgon1(:,2),ones(length(pgon1),1)*1,'b','facealpha',1)
patch(pgon2(:,1),pgon2(:,2),ones(length(pgon2),1)*2,'b','facealpha',0.75)
patch(pgon3(:,1),pgon3(:,2),ones(length(pgon3),1)*3,'b','facealpha',0.5)
patch(pgon4(:,1),pgon4(:,2),ones(length(pgon4),1)*4,'b','facealpha',0.3)
patch(pgon5(:,1),pgon5(:,2),ones(length(pgon5),1)*5,'b','facealpha',0.2)
In Matlab 2017b, the default heapmap color ranges from light blue to dark blue. How can I make zero values white instead of light blue (it is difficult to distinguish between low numbers and zero in the current form).
cdata = [0 0.005 1; 1 0 0.0006; 0.4 0.20 0.1];
h = heatmap(cdata);
You can change the color map zero values to white by changing the colormap values by
map=colormap(heatmap(cdata));
map(1,:)=1;
And when plotting the figure map use the defined color map as follows
h = heatmap(cdata,'Colormap',map);
I want to extract each colored region in MATLAB after applying SRM segmentation method on a particular image.
I tried the following, but it seems that it extracts regions with different color (not the same color degree only), and with the largest area.
I = imread('./img/bfly.jpg');
imshow(I)
bw = im2bw(I);
imshow(bw)
L = bwlabel(bw);
imshow(L == 0)
props = regionprops(L);
[~,ind] = max([props.Area]);
imshow(L == ind);
Is there a way to extract each color separately?
This is an example image. I want to extract the brown color alone, the green color alone, and so on ...
Since your image appears to have no smooth variations of color, it should be straightforward to separate the colors into different images with unique to convert the image to label matrix (you could do this with rgb2ind also) followed by accumarray:
[Iu,ia,iu] = unique(reshape(I,[],3),'rows');
counts = accumarray(iu,1);
[counts,sortinds] = sort(counts,'descend');
Now say you want the N largest components:
N = 10;
largestLabels = sortinds(1:N);
Then the image for color ii:
mapi = reshape(iu == largestLabels(ii),size(I,1),size(I,2));
numeli = counts(ii)
The corresponding RGB values and the number of pixels of each color:
>> colorRegionSummary = [uint32(Iu(largestLabels,:)) counts(1:N)]
colorRegionSummary =
89 120 23 8206 % green
73 59 42 4370 % dark brown (wing)
64 128 184 2723 % blue (right shade)
105 136 25 2143 % green (bottom right shade)
64 127 178 1667 % blue (top left shade)
170 151 191 1380 % purple
58 132 201 1372 % blue (left shade)
177 130 45 1242 % orange (bottom wing shade)
184 123 50 1193 % orange (top wing shade)
118 114 56 586 % tan (top right)
Note that these are not connected components, just components with the same color. For a given mapi, you can then apply bwlabel to get the connected components for that color.
You could start with encoding the three color arrays (RGB) in a way so that you can merge them into one, two-dimensional array, e.g.
2Dimage = I(:,:,1) + 1e3*I(:,:,2) + 1e6*I(:,:,3)
that way, you get a unique number for each color: R + 1e3*G + 1e6*B. Note that each channel is encoded with a number in the interval [0, 255].
Now you can go and extract the different color regions from the image using
C = unique(2Dimage)
to obtain the unique colors you need to look for and then
for idx = 1:length(C)
find(C(idx)==2Dimage)
end
to locate the different parts of the image. The color can be readily obtained from the original image I at the corresponding locations/indices.
How can I change the default white for zero for the output of a contour plot to a different color in MATLAB?
longitude = [80 82 95]
latitude = [30 32 35]
temp = [0 0 0; 0 0 0; 0 0 0]
contourf(longitude,latitude,temp)
Thanks,
Amanda
The key seems to be in the "renderer/rendering" mode from the figure properties. It must be set to either 'painters' or 'zbuffer'. I am not an expert and I didn't understand how to set it by default. I changed it manually through the figure editor (click on the outer figure frame --> More properties --> Renderer) and then I clicked "generate code" from the menu bar to make a function that automatically creates all plots in the same way.