Add multiply shapefiles in one figure (MATLAB) - matlab

I have 4 shape file. I know how to read them using this code:
% first shape file is for whole country
Country = 'country.shp'
S_country = shaperead (country);
M_country = mapshow (S_country); % >>>> I want to be in a white with black border <<<< can you please tell me how to?
% Second shape file for a sea in the north
north_sea = 'caspian sea.shp'
S_north_sea = shaperead (north_sea);
M_north_sea = mapshow (S_north_sea ); % I want to be in blue with no border
% Third shape file for a gulf in the south
Sout_gulf = 'persiangulf.shp'
S_Sout_gulf = shaperead (Sout_gulf);
M_Sout_gulf = mapshow (S_Sout_gulf); % I want to be in blue with no border
% Fourth Shape file for a sea in the south
south_sea = 'oman sea.shp'
S_south_sea = shaperead (south_sea);
M_south_sea = mapshow (S_south_sea); % I want to be in blue with no border
But I don't know how to have all of them in the one figure to have a nicely figure of a country with sea in north and south with colors that I mentioed in the comments of code.
I attach all 4 shape file here in my google drive.
Thank you.
Update
Thanks to your guidance in a comment below, I used this:
But still, I can't have all the figures in one
country = 'country.shp'
S_country = shaperead (country);
north_sea = 'caspian sea.shp'
S_north_sea = shaperead (north_sea);
figure
mapshow (S_country);
hold on
mapshow (S_north_sea );

Related

Making a colorbar's frame white while keeping the labels black

How can I make the rectangular line around the box of the colorbar white, but keep the tick labels black?
Reproducible code below:
colormap(flipud(autumn(6))); % Create Colormap
cb = colorbar; % Create Colorbar
cb.Ticks = [.1667 .3334 .5001 .6668 .8335]; % Create ticks
cb.TickLabels = ({'0%','5%','10%','15%','20%'});
cb.TickLength = 0;
cb.Color = 'w'; % Everything becomes white, I only want the rectangular color of the box to be white
You could get the wanted visual effect by overlaying a white annotation box on the colorbar, e.g.
colormap(flipud(autumn(6))); % Create Colormap
cb = colorbar; % Create Colorbar
cb.Ticks = [.1667 .3334 .5001 .6668 .8335]; % Create ticks
cb.TickLabels = ({'0%','5%','10%','15%','20%'});
cb.TickLength = 0;
% cb.Color = 'w'; % Everything becomes white, I only want the rectangular color of the box to be white
annotation('rectangle',cb.Position,'Color','w','FaceColor','none','LineWidth',2)
From the ColorBar properties documentation page we learn that the Color property changes too many things:
Color — Color of tick marks, text, and box outline
So we have to try something else. Fortunately, if you are comfortable with using an undocumented feature, the desired effect can be achieved by modifying the colorbar's Ruler property:
function [] = q66408322()
hF = figure();
hAx = axes(hF);
colormap(hAx, flipud(autumn(6)));
hCb = colorbar(hAx,...
'Ticks', [.1667 .3334 .5001 .6668 .8335],...
'TickLabels', {'0%','5%','10%','15%','20%'}, ...
'TickLength', 0, ...
'Color', 'w');
hCb.Ruler.Color = 'k'; % <<<<<< Solution
Resulting in:

How can I draw the rectangle including the surfPoints object on the image?

I have a grayscale image I want to extract the regions of interest using detectSURFFeatures(). Using this function I get a surfPoints object.
by displaying this object on the image I get circles as regions of interest.
For my case I want the rectangular areas encompassing these circles.
To be more clear i have a image 1:
I want to extract Region of Interest (ROI) using : detectSURFFeatures(), we obtain the image
if you can see we have circular region, and for my case i want the rectangular ROI that contains the circular region :
It looks like the radius is fully determined by the points.Scale parameter.
% Detection of the SURF features:
I = imread('cameraman.tif');
points = detectSURFFeatures(I);
imshow(I); hold on;
% Select and plot the 10 strongest features
p = points.selectStrongest(10)
plot(p);
% Here we add the bounding box around the circle.
c = 6; % Correction factor for the radius
for ii = 1:10
x = p.Location(ii,1); % x coordinate of the circle's center
y = p.Location(ii,2); % y coordinate of the circle's center
r = p.Scale(ii); % Scale parameter
rectangle('Position',[x-r*c y-r*c 2*r*c 2*r*c],'EdgeColor','r')
end
And we obtain the following result:
In this example the correction factor for the radius is 6. I guess that this value correspond to half of the default Scale propertie's value of a SURFPoints object (which is 12.0). But since there is no information about that in the documentation, I can be wrong. And be carreful, the scale parameter of each ROI is not the same thing as the scale propertie of a SURFPoints object.

Determine the white point in the image

RGB = imread('originalimg.png');
MyImrgb = reshape(im2double(RGB), [],3);
Imrgb = MyImrgb.^2.2; %gamma correction
[x, y, z] = size(Imrgb);
% ld % rg %yv
ldrgyv2rgbMat = [1,1,0.236748566577269;
1,-0.299338211934457,-0.235643322285071;
1,0.0137437185685517,1]; % B
MyImrgbCol = reshape(Imrgb * ldrgyv2rgbMat, size(RGB));
MyImldrgyvCol = reshape(reshape(MyImrgbCol, [],3) *inv(ldrgyv2rgbMat),size(MyImrgbCol));
imshow(MyImldrgyvCol)
I need to find the white point in the color image in a particular axis say x axis. How do I proceed about it?
In an image, every axis has its own color. The transition point from that color, say for example red to green, the midpoint would be the white point. How do I write a Matlab code to get that point?

How to segment a region in matlab

I want to segment a region from an image in MATLAB and display it in a different image file.
I have tried segmenting it but failed. I want to segment the region from 200:400(i.e. only the regions those are yellow and green)
I = imread('Intensity1.jpg');
imshow(I)
hold on
mask = false(size(I));
mask(200:400) = true;
visboundaries(mask,'Color','b');

Finding area in image with maximum variation of pixels

I am struggling with some algorithm to extract the region from an image which has the maximum change in pixels. I got the following image after preprocessing.
I did following steps of pre-processing
x = imread('test2.jpg');
gray_x = rgb2gray(x);
I = medfilt2(gray_x,[3 3]);
gray_x = I;
%%
canny_x = edge(gray_x,'canny',0.3);
figure,imshow(canny_x);
%%
s = strel('disk',3);
si = imdilate(canny_x,s);
%figure5
figure; imshow(si);
se = imerode(canny_x,s);title('dilation');
%figure6
figure; imshow(se);title('Erodsion');
I = imsubtract(si,se);
%figure7
figure; imshow(I);
Basically what I am struggling for, is to make weapon detection system using Image processing. I want to localize possible area's to be weapon so that I could feed them to my classifier to identify if it is a weapon or not. Any suggestions? Thank you
A possible solution could be:
Find corner points in the image (Harris corner points, etc)
Set value of all the corner points to white while remaining image will be black
Take a rectangular window and traverse it over the whole image
sum all the white pixels in that rectangular window
select that region whose sum is maximum of all regions