I have thousands of different sizes that I need to convert from feet and inches into inches using classic .asp.
The sizes are listed in the following format:
[width] x [height]
The width and height are shown with ' marks, which stand for feet and " marks which stand for inches.
For example, take the following and convert it into inches:
2'6" x 8' = width = 30; height = 96
9'6" x 13'6" = width = 120; height = 162
Sometimes there is no X in the size, indicating that it is round or square in shape. For example:
2'6"
That would have to make both the width and height the same, so:
2'6" = width = 30; height = 30
Sometimes, there is a trailing " at the end, where there should be inches, but there are none listed. For example:
5'0" x 8'" = width = 60; height = 96
I am guessing that I would need to create some sort of custom function with expressions, but just having a hard time figuring it out.
I tried creating the following function, but it only outputs the test size I created, 5' x 4'
'example source sizes
'5'2" X 4'3"
'4' X 3'
'3'4"
'5'
'23" X 21"
'21"
'then run the function
'idsize = GetInches(rs("size"))
dim idsize
idsize = "5' x 4'"
GetInches(idsize)
Response.Write (idsize)
Function GetInches(feet_inches)
dim sizehold
feet_inches = split(feet_inches,"X")
sizehold = split(feet_inches(0),"'")
feet_inches = sizehold(0)
feet_inches = replace(feet_inches,chr(34),"")
feet_inches = replace(feet_inches,"'","")
feet_inches = trim(feet_inches)
feet_inches = feet_inches * 12
End Function
Any pointers would be appreciated.
You'll need to search the string for an X and then use string split functions.
You can split on the X if it exists to start to split things out into the width and height. You should then be able to split on the single quote, convert the feet using *12 and add to the inches.
Remember that classic ASP is basically VB script so there's probably some code for this floating around on google.
Related
I managed to make a simple single stacked barplot (see code below and thanks for your help!), but now I'd need to make something more complex, please see attached figure (B) as an example. I'd like to plot the "Cell_number", and have a y-axis with numbers and small lines (right hand side of figure B) and next to it a barplot with cell fraction ("Percentage"). I do have 1 barplot per dataset. Many thanks in advance.
gplot(Data, aes(x = "", y = Percentage, fill = Cell_type)) +
geom_col(width = .25) +
scale_fill_manual(values = c("green3", "orange2", "lightskyblue2")) +
coord_flip() +
theme_minimal() +
labs(x= "metPAN TLS", y = "Cell types (%)") +
geom_text(aes(label = paste0(Percentage, "")),
position = position_stack(vjust = 0.5))enter code here
I want to find the size of an image (height, width, and area) and save the size value in txt file. I tried this command:
img = imread('TN4.jpg');
abu=rgb2gray(img);
imwrite(abu,'abu.jpg');
cb=imclearborder(abu);
imwrite(cb,'cb.jpg')
thresh=graythresh(cb);
b=im2bw(cb,thresh);
imwrite(b,'b.jpg');
bw=bwareaopen(b,100);
bwfill=imfill(bw,'holes');
imwrite(bwfill,'bw.jpg');
s = regionprops(bwfill,'BoundingBox');
out = bsxfun(#times,img,uint8(bwfill));
objects=cell(numel(s),1);
for idx = 1:numel(s)
bb=floor(s(idx).BoundingBox);
objects{idx} = out(bb(2):bb(2)+bb(4), bb(1):bb(1)+bb(3),:);
end
k1=objects{1};
c1=rgb2gray(k1);
t1=graythresh(c1);
biner1=im2bw(c1,t1);
[height, width] = size(biner1);
a1 = bwarea(biner1);
h1=height(biner1);
w1=width(biner1);
X = [(h1);(w1);(a1)];
save datagrading.txt X -ascii
but i got warning massage
??? Index exceeds matrix dimensions.
Error in ==> exercise at 35
h1=height(biner1);
can anyone help me?
Thank you
height and width are scalars yet (it looks like to me...) you are assuming that they are functions.... no they're not functions. Just use height and width on its own and place it into your X matrix:
[height, width] = size(biner1);
a1 = bwarea(biner1);
%h1=height(biner1); %// Remove
%w1=width(biner1); %// Remove
X = [height;width;a1]; %// Change
save datagrading.txt X -ascii
Since you have multiple objects and you want to save the height, width and area of these objects, just loop over each one, find the quantities you desire, place them into an overall matrix and save it:
X = zeros(3, numel(objects));
for k = 1 : numel(objects)
k1=objects{k}; %// Change
c1=rgb2gray(k1);
t1=graythresh(c1);
biner1=im2bw(c1,t1);
[height, width] = size(biner1);
a1 = bwarea(biner1);
X(:,k) = [height;width;a1];
end
save datagrading.txt X -ascii
X is now a 3 x s matrix where s is the total number of objects you have. Therefore, each column contains the height, width and area of each object.
You declared
[height, width] = size(biner1);
So height(biner1) will refer to the biner1-th element of height, which is not existent.
Use X = [(height);(width);(a1)]; instead.
I have created a big heat map using matlab's imagesc command. It plots the error output for each combination of the values in x and y axes. As can be seen in the figure there are too many axes labels. This might become even denser as I plan to increase the number of points in both x and y axes - which means I will get more outputs on a finer grid.
I want to be flexible with the labels, and skip some of them. I want to do this for both X and Y. I also want to be flexible with the "ticks" and draw either all of them or maybe skip some of them. Keep in mind that both the X and Y values are not increasing in order, at first the increment is 0.01 for 9 points, then 0.1, then 1 or 3 or whatever. I will change these increments too.
I tried to show what I want the graph look like in the second image. I want roughly the labels shown in red boxes only. As I said these are not set values, and I will make the increments smaller which will lead to denser plot.
Thank you for your help.
OS: Windows 7, 8 (64 bit)
Matlab version: Matlab 2014 a
You can manipulate the ticks and labels like this:
ticksarray=[1 33 41 100 ...] % edit these to whatever you want
tickslabels={'1', '33', '41', '100'; ...} % match the size of both arrays
set(gca,'XTick',ticksarray)
set(gca,'XTickLabel',tickslabels)
The same thing applies to the y-axis.
Small working example:
x=1:100;
y=2*x.^2-3*x+2;
plot(x,y)
ticksarray=[1 33 41 100];
tickslabels={'1', '33', '41', '100'};
set(gca,'XTick',ticksarray)
set(gca,'XTickLabel',tickslabels)
Example:
figure(1)
load clown
subplot(211)
imagesc(X);
subplot(212)
imagesc(X);
h = gca;
Now you can either set a maximum number of labels per axis:
%// define maximum number of labels
maxLabel = 3;
h.XTick = linspace(h.xlim(1),h.xlim(2),maxLabel);
h.YTick = linspace(h.ylim(1),h.ylim(2),maxLabel);
or define how many labels should be skipped:
%// define number of labels to skip
skipLabel = 2;
h.XTick = h.XTick(1:skipLabel:end);
h.YTick = h.YTick(1:skipLabel:end)
You can also get a different number of ticks and labels, more complicated though:
maxLabel = 3;
maxTicks = 6;
h.XTick = linspace(h.xlim(1),h.xlim(2),maxTicks);
h.YTick = linspace(h.ylim(1),h.ylim(2),maxTicks);
h.XTickLabel( setdiff( 1:maxTicks, 1:maxTicks/maxLabel:maxTicks ) ) = repmat({''},1,maxTicks-maxLabel);
h.YTickLabel( setdiff( 1:maxTicks, 1:maxTicks/maxLabel:maxTicks ) ) = repmat({''},1,maxTicks-maxLabel);
If you use a prior version of Matlab 2014b, then you will need the set command to set all properties:
%// define maximum number of labels
maxLabel = 3;
Xlim = get(h,'Xlim');
Ylim = get(h,'Ylim');
set(h,'XTick', linspace(Xlim(1),Xlim(2),maxLabel));
set(h,'YTick', linspace(Ylim(1),Ylim(2),maxLabel));
%// or define number of labels to skip
skipLabel = 2;
XTick = get(h,'XTick');
YTick = get(h,'YTick');
set(h,'XTick', XTick(1:skipLabel:end));
set(h,'YTick', YTick(1:skipLabel:end));
%// or combined
maxLabel = 3;
maxTicks = 6;
Xlim = get(h,'Xlim');
Ylim = get(h,'Ylim');
set(h,'XTick', linspace(Xlim(1),Xlim(2),maxTicks));
set(h,'YTick', linspace(Ylim(1),Ylim(2),maxTicks));
XTickLabel = cellstr(get(h,'XTickLabel'));
YTickLabel = cellstr(get(h,'YTickLabel'));
XTickLabel( setdiff( 1:maxTicks, 1:maxTicks/maxLabel:maxTicks ),: ) = repmat({''},1,maxTicks-maxLabel);
YTickLabel( setdiff( 1:maxTicks, 1:maxTicks/maxLabel:maxTicks ),: ) = repmat({''},1,maxTicks-maxLabel);
set(h,'XTickLabel',XTickLabel);
set(h,'YTickLabel',YTickLabel);
After applying the second method proposed by #thewaywewalk I got the second figure below. Apparently the labels need to be structured as well, because they only take the first so many labels.
Then I tried to manipulate the labels as shown below, and got the third image.
skipLabel = 2;
XTick = get(h,'XTick');
YTick = get(h,'YTick');
set(h,'XTick', XTick(1:skipLabel:end));
set(h,'YTick', YTick(1:skipLabel:end));
XTickLabel = get(h,'XTickLabel');
labelsX = cell( length(1: skipLabel:length(XTick)) , 1);
j = 1;
for i = 1: skipLabel:length(XTick)
labelsX{j} = XTickLabel(i, :);
j = j + 1;
end
set(h,'XTickLabel', labelsX);
YTickLabel = get(h,'YTickLabel');
labelsY = cell( length(1: skipLabel:length(YTick)) , 1);
j = 1;
for i = 1: skipLabel:length(YTick)
labelsY{j} = YTickLabel(i, :);
j = j + 1;
end
set(h,'YTickLabel', labelsY);
The Y axis labels seem to be in place as before (right next to tick), however the X axis labels seem to be shifted to the left a little. How can I correct this?
Another note: How can I change the scientific values into normal numbers? Also, probably there is a better approach at manipulating the labels.
I need some help with RGB capture in a image.
I am using impixel to manualy get RGB from a picture, but i would like to create a grid of let's say 20x20 px boxes where it will automatically tell me for each box a RGB value. So in a picture lets say i have 20 boxes it will tell me 20 RGB values. Yeah an if there is 20% or more of white space that it ignores that rgb box.
Can you point me to some links or give me a general idea how to do this.
Best regards
P.S. image is just a .jpg, the background is white an in the middle there is an item.
UPDATE
This is my code for collecting RGB using impixel
px=impixel(img);
st = num2cell(px,1);
zstup = cellfun(#sum,st);
zred = size(px,1);
rez = bsxfun(#rdivide,zstup,zred);
trez=round(rez);
What I want to do is :
http://imageshack.us/photo/my-images/696/exsample.jpg/
So every box like A1, A2, and so on will return RGB value like trez in my code.
So in my code i save my trez data in a table and it is like in excell lets say 220 | 23 | 34, now if i do that to another fruit i will have
220 | 23 | 34
123 | 212| 78
and so on...
Returning to automatization, A7 and A 15 would not be good RGB canditades because they have more then 50% white area so everything that has 20% white will be ignored.
So A31 is good and the RGB value needs to be saved.
So all in all here i would have my be 6 RGB values that would have to be automatically saved like the above example.
I know how to save to table i just need help for the gathering rgb values in every box.
Depending on your exact needs I see two solutions:
Downscale the image using impyramid(img, 'reduce'). This gives you a smaller image consisting of average values of the original image. Then do what you did before to access single pixels. Repeat as often as necessary to get 2x2, 4x4, 8x8 or larger "boxes".
Or you could use define a box (or arbitrary shape) as a matrix of ones and zeros and use the regionprops function in order to get information about the images content depending on the fields containing ones:
roi = zeros(size(img))
roi(1:10,1:10) = 1;
r = regionprops(roi, img, 'MeanIntensity')
average = r.MeanIntensity
This is my complete code for automatic color grabing from pictures in folder. So the program asks you to chose a folder and after that you get a table full of information about color and roundess. I am using this code to get color from fruits that have white background . It does everything by itself. Hope it helps someone.
clear all;
clc;
uiwait(msgbox('Chose the folder where your pictures are kept. Click OK to continue..'));
% Opening the folder
folder = uigetdir(pwd);
filePattern = fullfile(folder, '*.jpg');
jpegFiles = dir(filePattern);
for k = 1:length(jpegFiles)
baseFileName = jpegFiles(k).name;
fullFileName = fullfile(folder, baseFileName);
[pathstr, name, ext] = fileparts(fullFileName);
naziv_voca=name;
%Taking RGB color
slika = imread(fullFileName);
[redovi stupci RGBboje] = size(slika);
red_ink = floor(redovi/10);
stup_ink = floor(stupci/10);
r = 1;
c = 1;
for stupac = 1 : stup_ink : stupci
for red = 1 : red_ink : redovi
red1 = red;
red2 = red1 + red_ink;
stupac1 = stupac;
stupac2 = stupac1 + stup_ink;
red2 = min(red2, redovi);
stupac2 = min(stupac2, stupci);
crveniS = slika(red1:red2, stupac1:stupac2, 1);
zeleniS = slika(red1:red2, stupac1:stupac2, 2);
plaviS = slika(red1:red2, stupac1:stupac2, 3);
crvena(r,c) = mean2(crveniS);
zelena(r,c) = mean2(zeleniS);
plava(r,c) = mean2(plaviS);
r = r + 1;
if r >redovi
r = 1;
end
end
c = c + 1;
if c >1
c = 1;
end
end
RGB=[crvena,zelena,plava];
bijela=[255 255 255];
tolerancija = 50;
rez = RGB((abs(RGB(:,1)-bijela(1)) > tolerancija) | (abs(RGB(:,2)-bijela(2)) > tolerancija),:);
trez=round(rez);
%Taking shape
pic = rgb2gray(slika);
threshold = graythresh(pic);
bw = im2bw(pic,threshold);
fbw = ones(size(bw))-imfill(ones(size(bw))-bw);
invImg = ~fbw;
f = bwlabel(invImg);
S = regionprops(f,'Area','Perimeter','centroid');
Thr=100;
S=S([S.Area]>Thr);
score = (min(sqrt([S.Area]),[S.Perimeter]/4)./(max(sqrt([S.Area]), [S.Perimeter]/4))).^2;
score=max(score);
%Inserting data into table and creating data
if exist('tablica.mat','file')
vel=size(trez,1);
for z=1:vel
s=load('tablica');
olddata=s.data;
temp=trez(z,:);
dataCell= [naziv_voca,num2cell(temp),num2cell(score)];
data=[olddata;dataCell];
save('tablica.mat','-append','data');
end
else
stupac_rgb = num2cell(trez,1);
zstupac = cellfun(#sum,stupac_rgb);
zred = size(trez,1);
rez = bsxfun(#rdivide,zstupac,zred);
trez=round(rez);
data= [naziv_voca,num2cell(trez),num2cell(score)];
save('tablica','data')
end
end
uiwait(msgbox('Your information is saved'));
I developed an app to read distance between two locations on windows phone 7 . But while testing the app, whenever i move some centimeters, it starts to give value in 13000's.
Public Sub watcher1_PositionChanged(sender As Object, e As GeoPositionChangedEventArgs(Of GeoCoordinate))
Dim dCoord As GeoCoordinate
Dim currentDistance As Double
Dim convertedDistance As Double
dCoord = New GeoCoordinate(e.Position.Location.Latitude, e.Position.Location.Longitude)
If mlastCoordinate.Latitude <> 0.0 Then
'distanceText.Text = e.Position.Location.Latitude.ToString()
currentDistance = mlastCoordinate.GetDistanceTo(dCoord)
mDistance = startCoordinate.GetDistanceTo(dCoord)
' mDistance += currentDistance
'mDistance = Math.Round(mDistance, 2)
'Dim distance As String
'distance = String.Format("%.2", mDistance)
If selectedSystemState.Equals("centi") Then
convertedDistance = mDistance * 100
ElseIf selectedSystemState.Equals("meter") Then
convertedDistance = mDistance
ElseIf selectedSystemState.Equals("inches") Then
convertedDistance = mDistance * 39.37
ElseIf selectedSystemState.Equals("feet") Then
convertedDistance = mDistance * 3.28
End If
convertedDistance = Math.Round(convertedDistance, 2)
The distance you are getting is in meters. So, 13000 centimeters is 130 meters - unless we know what and how you move, this seems like a very plausible value.
How are you instantiating the Location Service - If you're not using GeoCoordinateWatcher(GeoPositionAccuracy.High) you'll likely be using Cell Tower data, which can be off by many 100s of metres.
Even if you are using GPS the accuracy of civilian GPS units is only in the order of 5-10m, so measuring distances in cm or inches is really beyond these things.
You should probably check the GeoCoordinate.HorizontalAccuracy to see what the "noise" is likely to be.