Increase the size of label at the top of plot using fviz_screeplot function: I want to increase the size of the label at the top of bar - visualization

My_Theme <- theme(axis.title.x = element_text(size = 24),axis.text.x =
element_text(size = 20),axis.text.y = element_text(size = 20),axis.title.y = element_text(size = 24),plot.title = element_text(size = 25))
tt <- fviz_screeplot(t3.mfa, choice = "variance", barfill = "white",
barcolor="steelblue",linecolor="red", ncp = 16, addlabels = TRUE, hjust = 0, main = NULL,
xlab = NULL, ylab = NULL)
mytt <- tt + My_Theme + theme(plot.title = element_text(hjust = 0.5))
myttt <- mytt + labs(title = "Variances - MFA", x = "Principal Components", y = "% of variances")
myttt + theme(panel.grid.major = element_blank(),panel.grid.minor = element_blank())

Related

How do I create an alert for a plotshape with an offset of -10, such that when the plotshape is displayed on the chart, an alert would trigger

I tried creating a label with an offset and having the alert trigger from the label displayed on the chart but I'm stuck at this point
prd = input.int(defval=10, title='Pivot Period', minval=4, maxval=30, group='Setup')
float src1 = ppsrc == 'High/Low' ? high : math.max(close, open)
float src2 = ppsrc == 'High/Low' ? low : math.min(close, open)
float ph = ta.pivothigh(src1, prd, prd)
float pl = ta.pivotlow(src2, prd, prd)
plotshape(ph and src1, style=shape.triangledown, text='SELL(H)', color=na, textcolor=color.new(#eeff00, 0), location=location.abovebar, offset=-prd)
plotshape(pl and src2, style=shape.triangleup, text='BUY(L)', color=na, textcolor=color.new(#ffffff, 0), location=location.belowbar, offset=-prd)
Lstyle = linestyle == 'Dashed' ? line.style_dashed : linestyle == 'Solid' ? line.style_solid : line.style_dotted
labeloffset = prd
labelcolor = color.red
labeltext = "Sell(R)"
labelcolor2 = color.green
labeltext2 = "Buy(S)"
value1 = ph and src1
value2 = pl and src2
var label ourlabel = na
label_ph = label.new(x = bar_index - labeloffset, y = na, text = labeltext, color = labelcolor, xloc = xloc.bar_index, yloc = yloc.abovebar, textcolor = color.white, style = label.style_label_down, size = size.normal, tooltip = "pl_label_id")
label_pl = label.new(x = bar_index - labeloffset, y = na, text = labeltext2, color = labelcolor2, xloc = xloc.bar_index, yloc = yloc.belowbar, textcolor = color.white, style = label.style_label_up, size = size.normal, tooltip = "ph_label_id")
// Defined my conditions for the label
if ph and src1
label_ph
else
label.delete(ourlabel)
if pl and src2
label_pl
else
label.delete(ourlabel)

How to create object within function MatLab without creating a new file

I am working on a project with the following specs:
https://drive.google.com/file/d/14xaCK-1Mpd8FXM-19pfFC1UTk2V9oXkQ/view?usp=sharing
My code is attached below.
How do I get my final output as a data object and info object like they are asking, without creating a new class file? The format required is in the picture below.
Final format required:
function [data,info] = OneNormLPxxx(A,b)
%L1 norm minimization for a given A and b.
% Detailed explanation goes here
count = 0;
b_vect = b;
[m,n] = size(A);
max_count = 3*nchoosek(m,n);
set_B = 1:n;
M = inv(A(set_B, :));
is_opt = 0;
while (is_opt == 0)
if (det(A(set_B,:)) == 0)
info = untitled4;
info.run = "Failure";
info.msg = "Degeneracy Problem";
data = untitled3;
return
end
if (max_count <= count)
info = untitled4;
info.run = "Failure";
info.msg = "Arithmetic Problem";
data = untitled3;
return
end
set_B_Comp = setdiff(1:m,set_B);
x_temp = M*b_vect(set_B);
h = A*x_temp - b_vect;
h(set_B_Comp) = A(set_B_Comp,:)*x_temp - b_vect(set_B_Comp);
y_vect = zeros(m, 1);
y_vect(set_B_Comp) = sign(h(set_B_Comp));
y_vect(set_B) = -(M')*((A(set_B_Comp,:)')*y_vect(set_B_Comp));
abs_y_B = abs(y_vect(set_B));
if all(abs_y_B <= 1)
is_opt = 1;
x_opt = x_temp;
opt_val = sum(abs(A*x_opt - b_vect));
data = untitled3;
data.obj = opt_val;
data.x = x_opt;
data.loop = count;
info = untitled4;
info.run = "Success";
return
% return B and x
else
all_index_y_vect_more_than_1 = find(abs(y_vect(set_B)) > 1);
s = all_index_y_vect_more_than_1(1);
y_s = y_vect(s);
t_vect = zeros(m, 1);
t_vect(set_B_Comp) = -(sign(y_s))*(y_vect(set_B_Comp)).*(A(set_B_Comp,:)*M(:,s));
cur_min = abs(h(set_B_Comp(1)))/t_vect(set_B_Comp(1)) + 1;
cur_r = set_B_Comp(1);
for j = set_B_Comp
h_j = h(j);
t_j = t_vect(j);
temp1 = abs(h_j)/t_j;
if (temp1 < cur_min) && (temp1 > 0) && (t_j > 0)
cur_min = temp1;
cur_r = j;
end
end
r = cur_r;
j_s = set_B(s);
set_B_new = setdiff(union(set_B, r), j_s);
set_B = set_B_new;
set_B_Comp = setdiff(1:m,set_B);
theta = (A(r,:)*M)';
M(:,s) = (1/theta(s))*M(:,s);
for j = 1:n
if (j ~= s)
M(:,j) = M(:,j) - theta(j)*M(:,s);
end
end
end
count = count + 1;
end
end
Rather than using
info = untitled4;
Use
info = struct();
This will create a MATLAB structure for storing your data.

Matlab. How to implement tracking with counter on top of boxes?

Hello I have tried using the example in
https://www.mathworks.com/help/vision/examples/tracking-pedestrians-from-a-moving-car.html and now I want to add a counter to replace the score. I have tried mixing the example in https://www.mathworks.com/help/vision/examples/motion-based-multiple-object-tracking.html. I have tried using the method it use to add in counter above the box. but to no avil.
Below are the codes.
function PedestrianTrackingFromMovingCameraExample()
videoFile = 'vippedtracking.mp4';
scaleDataFile = 'pedScaleTable.mat'; % An auxiliary file that helps to determine the size of a pedestrian at different pixel locations.
video = VideoReader(videoFile);
obj = setupSystemObjects(videoFile, scaleDataFile);
detector = peopleDetectorACF('caltech');
tracks = initializeTracks();
nextId = 1;
option.scThresh = 0.3;
option.gatingThresh = 0.9;
option.gatingCost = 100;
option.costOfNonAssignment = 10;
option.timeWindowSize = 16;
option.confidenceThresh = 2;
option.ageThresh = 8;
option.visThresh = 0.6;
while hasFrame(video)
frame = readFrame();
[centroids, bboxes, scores] = detectPeople();
predictNewLocationsOfTracks();
[assignments, unassignedTracks, unassignedDetections] = ...
detectionToTrackAssignment();
updateAssignedTracks();
updateUnassignedTracks();
deleteLostTracks();
createNewTracks();
displayTrackingResults();
if ~isOpen(obj.videoPlayer)
break;
end
end
function obj = setupSystemObjects(videoFile,scaleDataFile)
obj.reader = vision.VideoFileReader(videoFile, 'VideoOutputDataType', 'uint8');
obj.videoPlayer = vision.VideoPlayer('Position', [29, 597, 643, 386]);
ld = load(scaleDataFile, 'pedScaleTable');
obj.pedScaleTable = ld.pedScaleTable;
end
function tracks = initializeTracks()
tracks = struct(...
'id', {}, ...
'color', {}, ...
'bboxes', {}, ...
'scores', {}, ...
'kalmanFilter', {}, ...
'age', {}, ...
'totalVisibleCount', {}, ...
'confidence', {}, ...
'predPosition', {}, ...
'consecutiveInvisibleCount', {});
end
function frame = readFrame()
frame = step(obj.reader);
end
function [centroids, bboxes, scores] = detectPeople()
resizeRatio = 1.5;
frame = imresize(frame, resizeRatio, 'Antialiasing',false);
[bboxes, scores] = detect(detector, frame, ...
'WindowStride', 2,...
'NumScaleLevels', 4, ...
'SelectStrongest', false);
height = bboxes(:, 4) / resizeRatio;
y = (bboxes(:,2)-1) / resizeRatio + 1;
yfoot = min(length(obj.pedScaleTable), round(y + height));
estHeight = obj.pedScaleTable(yfoot);
invalid = abs(estHeight-height)>estHeight*option.scThresh;
bboxes(invalid, :) = [];
scores(invalid, :) = [];
[bboxes, scores] = selectStrongestBbox(bboxes, scores, ...
'RatioType', 'Min', 'OverlapThreshold', 0.6);
if isempty(bboxes)
centroids = [];
else
centroids = [(bboxes(:, 1) + bboxes(:, 3) / 2), ...
(bboxes(:, 2) + bboxes(:, 4) / 2)];
end
end
function predictNewLocationsOfTracks()
for i = 1:length(tracks)
bbox = tracks(i).bboxes(end, :);
predictedCentroid = predict(tracks(i).kalmanFilter);
tracks(i).predPosition = [predictedCentroid - bbox(3:4)/2, bbox(3:4)];
end
end
function [assignments, unassignedTracks, unassignedDetections] = ...
detectionToTrackAssignment()
predBboxes = reshape([tracks(:).predPosition], 4, [])';
cost = 1 - bboxOverlapRatio(predBboxes, bboxes);
cost(cost > option.gatingThresh) = 1 + option.gatingCost;
[assignments, unassignedTracks, unassignedDetections] = ...
assignDetectionsToTracks(cost, option.costOfNonAssignment);
end
function updateAssignedTracks()
numAssignedTracks = size(assignments, 1);
for i = 1:numAssignedTracks
trackIdx = assignments(i, 1);
detectionIdx = assignments(i, 2);
centroid = centroids(detectionIdx, :);
bbox = bboxes(detectionIdx, :);
correct(tracks(trackIdx).kalmanFilter, centroid);
T = min(size(tracks(trackIdx).bboxes,1), 4);
w = mean([tracks(trackIdx).bboxes(end-T+1:end, 3); bbox(3)]);
h = mean([tracks(trackIdx).bboxes(end-T+1:end, 4); bbox(4)]);
tracks(trackIdx).bboxes(end+1, :) = [centroid - [w, h]/2, w, h];
tracks(trackIdx).age = tracks(trackIdx).age + 1;
tracks(trackIdx).scores = [tracks(trackIdx).scores; scores(detectionIdx)];
tracks(trackIdx).totalVisibleCount = ...
tracks(trackIdx).totalVisibleCount + 1;
tracks(trackIdx).consecutiveInvisibleCount = 0;
T = min(option.timeWindowSize, length(tracks(trackIdx).scores));
score = tracks(trackIdx).scores(end-T+1:end);
tracks(trackIdx).confidence = [max(score), mean(score)];
end
end
function updateUnassignedTracks()
for i = 1:length(unassignedTracks)
idx = unassignedTracks(i);
tracks(idx).age = tracks(idx).age + 1;
tracks(idx).bboxes = [tracks(idx).bboxes; tracks(idx).predPosition];
tracks(idx).scores = [tracks(idx).scores; 0];
tracks(idx).consecutiveInvisibleCount = ...
tracks(idx).consecutiveInvisibleCount + 1;
T = min(option.timeWindowSize, length(tracks(idx).scores));
score = tracks(idx).scores(end-T+1:end);
tracks(idx).confidence = [max(score), mean(score)];
end
end
function deleteLostTracks()
if isempty(tracks)
return;
end
ages = [tracks(:).age]';
totalVisibleCounts = [tracks(:).totalVisibleCount]';
visibility = totalVisibleCounts ./ ages;
confidence = reshape([tracks(:).confidence], 2, [])';
maxConfidence = confidence(:, 1);
lostInds = (ages <= option.ageThresh & visibility <= option.visThresh) | ...
(maxConfidence <= option.confidenceThresh);
tracks = tracks(~lostInds);
end
function createNewTracks()
unassignedCentroids = centroids(unassignedDetections, :);
unassignedBboxes = bboxes(unassignedDetections, :);
unassignedScores = scores(unassignedDetections);
for i = 1:size(unassignedBboxes, 1)
centroid = unassignedCentroids(i,:);
bbox = unassignedBboxes(i, :);
score = unassignedScores(i);
kalmanFilter = configureKalmanFilter('ConstantVelocity', ...
centroid, [2, 1], [5, 5], 100);
newTrack = struct(...
'id', nextId, ...
'color', 255*rand(1,3), ...
'bboxes', bbox, ...
'scores', score, ...
'kalmanFilter', kalmanFilter, ...
'age', 1, ...
'totalVisibleCount', 1, ...
'confidence', [score, score], ...
'predPosition', bbox, ...
'consecutiveInvisibleCount', 0);
tracks(end + 1) = newTrack; %#ok<AGROW>
nextId = nextId + 1;
end
end
function displayTrackingResults()
displayRatio = 4/3;
frame = imresize(frame, displayRatio);
minVisibleCount = 8;
if ~isempty(tracks)
reliableTrackInds = ...
[tracks(:).totalVisibleCount] > minVisibleCount;
reliableTracks = tracks(reliableTrackInds);
ids = int32([reliableTracks(:).id]);
labels = cellstr(int2str(ids'));
predictedTrackInds = ...
[reliableTracks(:).consecutiveInvisibleCount] > 0;
isPredicted = cell(size(labels));
isPredicted(predictedTrackInds) = {'predicted'};
labels = strcat(labels, isPredicted);
ages = [tracks(:).age]';
confidence = reshape([tracks(:).confidence], 2, [])';
maxConfidence = confidence(:, 1);
avgConfidence = confidence(:, 2);
opacity = min(0.5,max(0.1,avgConfidence/3));
noDispInds = (ages < option.ageThresh & maxConfidence < option.confidenceThresh) | ...
(ages < option.ageThresh / 2);
for i = 1:length(tracks)
if ~noDispInds(i)
bb = tracks(i).bboxes(end, :);
bb(:,1:2) = (bb(:,1:2)-1)*displayRatio + 1;
bb(:,3:4) = bb(:,3:4) * displayRatio;
frame = insertObjectAnnotation(frame, ...
'rectangle', bb, ...
labels, ...
'Color', tracks(i).color);
end
end
end
step(obj.videoPlayer, frame);
end
end

Move y axis labels to left side of heatmap.2

I would like to move the y-axis labels to the left side of heatmap.2. (This is similar, but not the same, as the question regarding moving the axis on heatmap)
While I am able to move the axis by editing line 290 of the heatmap.2 function, it the values then overwrite the actual heatmap.
if (is.null(srtRow) && is.null(colRow)) {
axis(4, iy, labels = labRow, las = 2, line = -0.5 + offsetRow,
tick = 0, cex.axis = cexRow, hadj = adjRow[1], padj = adjRow[2])
}
else {
if (is.null(srtRow) || is.numeric(srtRow)) {
xpd.orig <- par("xpd")
par(xpd = NA)
ypos <- axis(4, iy, labels = rep("", nr), las = 2, #change
line = -0.5, tick = 0)
text(x = par("usr")[2] + (1 + offsetRow) * strwidth("M"),
y = ypos, labels = labRow, adj = adjRow, cex = cexRow,
srt = srtRow, col = colRow)
par(xpd = xpd.orig)
}
I tried moving the location of the heatmap.2 by mucking about with the lwid and lhei options, but the overwrite problem persisted.
Thank you
Eric

Face detection using color feature

I am trying to detect faces in my picture. So I found a code that do this, but depending on my picture-input sometimes it finds the faces and for other pictures it doesn't work.
So I thought it because of the face's color of person that is on the picture. So when I change the thresholds value sometimes it make to work.
My thresholds value:
%Threshold
hlow = 0.0; hhigh = 0.4;
slow = 0.3; shigh = 0.8;
vlow = 0.4; vhigh = 0.9;
Blob_Threshold = 120;
Edge_Threshold = 650;
Edge_Tolerance = 500;
Percentage_Threshold = 35;
Tolerance = 0.25;
and it here is my code :
function [Faces_List inx_face] = FaceDetection(img)
%----------------Initialization----------------------
Temp_img = img;
img_height = size(Temp_img,1); % tedade satr
img_width = size(Temp_img,2); % tedade sotoona
Temp_img = im2double(Temp_img);
Skin = zeros(img_height,img_width);
%Threshold
hlow = 0.0; hhigh = 0.4;
slow = 0.3; shigh = 0.8;
vlow = 0.4; vhigh = 0.9;
Blob_Threshold = 120;
Edge_Threshold = 650;
Edge_Tolerance = 500;
Percentage_Threshold = 35;
Tolerance = 0.25;
goldenRatio = (1+sqrt(5))/2;
%----------------Convert Color Space From RGB2HSV----
Temp_img = rgb2hsv(Temp_img);
for i = 1:img_height
for j = 1:img_width
H = Temp_img(i,j,1);
S = Temp_img(i,j,2);
V = Temp_img(i,j,3);
bh = H >= hlow && H <= hhigh;
bs = S >= slow && S <= shigh;
bv = V >= vlow && V <= vhigh;
if (bh && bs && bv)
Skin(i,j) = 1;
end
end
end
figure;imshow(Skin);title('Skin Color Detection');
%----------------Initialization----------------------
%Skin_Blob = bwconncomp(Skin,8);
[Skin_Blob,Blob_Number] = bwlabel(Skin);
BlobData = regionprops(Skin_Blob,'all');
%Blob_Number = Skin_Blob.NumObjects;
inx_face = 0;
Faces_List = [];
%----------------Main Face Detection-----------------
for i = 1:Blob_Number
if (BlobData(i).Area > Blob_Threshold)
myFace = BlobData(i).Image;
figure;imshow(myFace);
%pause(1);
myHeight = size(myFace,1);%height
myWidth = size(myFace,2);%width
b1 = (myHeight/myWidth) >= goldenRatio - Tolerance;
b2 = (myHeight/myWidth) <= goldenRatio + Tolerance;
b3 = (myWidth/myHeight) >= goldenRatio - Tolerance;
b4 = (myWidth/myHeight) <= goldenRatio + Tolerance;
Percentage_skin = (sum(myFace(:)) / (myHeight * myWidth)) * 100;
b5 = Percentage_skin > Percentage_Threshold;
boundingBox = BlobData(i).BoundingBox;
x1 = fix(boundingBox(1));
y1 = fix(boundingBox(2));
x2 = fix(boundingBox(3));
y2 = fix(boundingBox(4));
edgeFace = imcrop(img,[x1 y1 x2 y2]);
imGray = rgb2gray(edgeFace);
imEdge = edge(imGray,'sobel');
sumEdge = sum(imEdge(:));
b6 = sumEdge >= Edge_Threshold - Edge_Tolerance;
b7 = sumEdge <= Edge_Threshold + Edge_Tolerance;
if (((b1 && b2) || (b3 && b4)) && b5 && (b6 && b7))
inx_face = inx_face + 1;
Faces_List(inx_face).x1 = x1;
Faces_List(inx_face).y1 = y1;
Faces_List(inx_face).x2 = x2;
Faces_List(inx_face).y2 = y2;
end
end %end if
end %for i
end%Function