I have an image with three phases with different grey-values ( Black, Grey [85 - 110] and another grey [115 - 148] ). I get the segmentation between all phases but I have a boundary condition that has to be taken into account:
Between the black phase and the third phase there are some pixels (more than 5 pixels) with values of the second phase. I want to add these pixels to the third phase because they only appear due to a contrast change between the two phases (1 and 3).
The program is:
Bild1 = imread('croped0015.tif');
for j=1:size(Bild1,2)
for l=1:size(Bild1,1)
if max(Bild1(l:l+5,j))<85 && min(Bild1(l+5:l+10,j))> 123 && min(Bild1(l+10:l+15,j))<123
Bild1(l+5:l+10,j)=min(Bild1(l+10:l+15,j));
end
if max(Bild1(l:l+5,j))<123 && min(Bild1(l+5:l+10,j))> 123 && min(Bild1(l+10:l+15,j))<85
Bild1(l+5:l+10,j)= min(Bild1(l:l+5,j));
end
if (l+16)>=size(Bild1,1)
break;
end
end
end
imshow(Bild1)
impixelregion
How can I use a region growth algorithm for this?
Related
I want to fix the attached pine script code in version 5 of Tradingview for a strategy I formed which is highly profitable but the signals for Buy, Sell, Exit Buy and Exit Sell are not occurring on the chart at the right points.
If someone can help me fix the attached code it would be great for even them as the strategy is highly profitable in trending markets and can be easily used to implement on a Trading Bot.
The strategy is as follows
I have 2 Exponential Moving Averages plotted on the chart, mainly EMA of 144 and EMA of 169. Once you plot these EMA's on the chart, they appear like a tunnel.
Buy Condition is - If the candle closes above both the EMA's, then a Buy Plot shape should occur on that candle.
Exit Buy Condition is - if the candle breaks the low of both the EMA's, even if not on a closing basis (even if the low of the candle is below both the EMA's), then a Exit Buy Plot shape should occur on that candle.
Sell Condition is - If the candle closes below both the EMA's, then a Sell Plot shape should occur on that candle.
Exit Sell Condition is - if the candle breaks the high of both the EMA's, even if not on a closing basis (even if the high of the candle is above both the EMA's), then a Exit Buy Plot shape should occur on that candle.
Also the most important aspect is that these shapes should not occur repeatedly. They should only occur on the specific candle when the condition is met.
I have attached the current pinescript code that I drafted but it isint working properly.
//#version=5
indicator("WavyCrorepati v2.0", overlay=true)
tunnel1 = ta.ema(close, 144)
tunnel2 = ta.ema(close, 169)
plot(tunnel1, color=color.white, linewidth=2)
plot(tunnel2, color=color.white, linewidth=2)
intradelong = 0
intradeshort = 0
// BUY
long = close > tunnel1 and close > tunnel2 or (ta.crossover(close,tunnel1) and ta.crossover(close,tunnel2))
if long
intradelong := 10
exitlong = low < tunnel2 and low < tunnel1
if exitlong
intradelong := 5
// SHORT
short = close < tunnel1 and close < tunnel2 or (ta.crossunder(close, tunnel1) and ta.crossunder(close, tunnel2))
if short
intradeshort := -10
exitshort = high > tunnel1 and high > tunnel2
if exitshort
intradeshort := -5
// PLOT SHAPES
plotshape(long and intradelong[1] == 5 , style=shape.labelup, color=color.green, location=location.belowbar, size=size.small,text="B",textcolor=color.white)
plotshape(exitlong and long[1], style=shape.diamond,color=color.white,location=location.belowbar,size=size.tiny)
plotshape(short and intradeshort[1] == -5 , style=shape.labeldown, color=color.red, location=location.abovebar, size=size.small,text="S",textcolor=color.yellow)
plotshape(exitshort and short[1], style=shape.diamond,color=color.yellow, location=location.abovebar,size=size.tiny)
plot(intradelong, color = color.green, display = display.status_line)
plot(intradeshort, color = color.red, display = display.status_line)
I can get the drop contour through a GetDropProfile command.
However, I can't find the conversion factor from pixels to millimeters. As the contour of the drop is obtained point by point starting from left to right, then the first ordered pair in the list gives the coordinates of the first pixel on the left. Consequently, the last ordered pair gives the value of the last pixel on the right. Since they are opposite each other, they therefore have the same y, so the difference in x of these two points is the diameter of the drop. How can I automate this process of converting pixels into millimeters and viewing the graph in millimeters, smoothing the contour of the discrete curve automatically giving us how many points to the right and left we should take?
It follows the image of the drop and the contour in pixels obtained.
As posted here, assuming the axes are in millimetres, the scale can be obtained from the x-axis ticks, which can be sampled from the row 33 from the bottom. As can be observed by executing the code below, the left- and rightmost ticks occupy one pixel each, coloured RGB {0.4, 0.4, 0.4}. So there are 427 pixels per 80mm.
img = Import["https://i.stack.imgur.com/GIuYq.png"];
{wd, ht} = ImageDimensions[img];
data = ImageData[img];
(* View the left- and rightmost pixel data *)
Take[data[[-33]], 20]
Take[data[[-33]], -20]
p1 = LengthWhile[data[[-33]], # == {1., 1., 1.} &];
p2 = LengthWhile[Reverse[data[[-33]]], # == {1., 1., 1.} &];
p120 = wd - p1 - p2 - 1
427
(* Showing the sampled row in the graphic *)
data[[-33]] = ConstantArray[{1, 0, 0}, wd];
Graphics[Raster[Reverse[data]]]
You might ask about smoothing the curve here https://mathematica.stackexchange.com
We are working on DIP project where we found out the threshold of the gray scale image. Now we have to * find the maximum intensity of the two regions that we got, one region whose pixels are less than the threshold and the other whose pixels are greater than it. *
PS. We are not converting the image into binary image after finding the threshold. We just have to separate pixels in two regions and find the maximum intensity in each region
PS: We are working on MATLAB
Actually it is pretty simple to do.
Here is a function to do so:
function [ lowThrMaxIntns, highThrMaxIntns ] = FindMaxIntnesity ( mInputImage, thrLevel )
% Pixels which are lower than the threshold level
mLowThrImage = zeros(size(mInputImage));
% Pixels which are higher than the threshold level
mHightThrImage = zeros(size(mInputImage));
mLowThrImage(mInputImage < thrLevel) = mInputImage(mInputImage < thrLevel);
mHightThrImage(mInputImage >= thrLevel) = mInputImage(mInputImage >= thrLevel);
[lowThrMaxIntns lowThrMaxIntnsIdx] = max(mLowThrImage(:));
[highThrMaxIntns highThrMaxIntnsIdx] = max(mHightThrImage(:));
end
The output are only the intensities of the pixels.
If you need the pixel location, use the Idx variables (Use ind2sub for the sub scripts form).
Below is one of the facebook puzzle:
I am not able to understand how to proceed for this.
You are given C containers, B black balls and an unlimited number of white balls. You want to distribute balls between the containers in a way that every container contains at least one ball and the probability of selecting a white ball is greater or equal to P percent. The selection is done by randomly picking a container followed by randomly picking a ball from it.
Find the minimal required number of white balls to achieve that.
INPUT
The first line contains 1 <= T <= 10 - the number of testcases.
Each of the following T lines contain three integers C B P separated by a single space 1<= C <= 1000; 0 <= B <= 1000; 0 <= P <= 100;
OUTPUT
For each testcase output a line containing an integer - the minimal number of white balls required. (The tests will assure that it's possible with a finite number of balls)
SAMPLE INPUT
3
1 1 60
2 1 60
10 2 50
SAMPLE OUTPUT
2
2
8
EXPLANATION
In the 1st testcase if we put 2 white balls and 1 black ball in the box the probability of selecting a white one is 66.(6)% which is greater than 60%
In the 2nd testcase putting a single white ball in one box and white+black in the other gives us 0.5 * 100% + 0.5 * 50% = 75%
For the 3rd testcase remember that we want at least one ball in each of the boxes.
You will probably have to do the following:
Initial no. of white balls Nw = 1.
Given the number of white balls, Nw, find the configuration that gives the maximum probability of picking a white ball.
Check if this probability is greater than P.
If yes, then Nw is your answer, else, increment Nw and goto 1.
Ofcourse the challenge is to find the best configuration in Step 1.
EDIT: The problem now boils down to given W white balls, B black balls, and C containers, find the configuration that gives the maximum probability of picking a white ball.
P = ( w1/(w1+b1) + w2/(w2+b2) + ... + wc/(wc+bc) ) /c.
Max(P) = Max ( w1/(w1+b1) + w2/(w2+b2) + ... + wc/(wc+bc) )
Given: summation(wi) = W, summation(bi) = B, wi + bi >= 1
I am guessing that the configuration shall be such that if there are N containers having white balls, then atleast N-1 shall have only 1 white ball and no black balls and at most 1 container shall have both white balls and black balls. Just a guess though...
I have performed rgb2gray on an image and did a sobel edge detection on the image.
then did
faceEdges = faceNoNoise(:,:) > 50; %binary threshold
so it sets the outline of the image (a picture of a face), to black and white. Values 1 is white pixel, and 0 is black pixel. Someone said I could use this,
mouthsquare = rectangle('position',[recX-mouthBoxBuffer, recY-mouthBoxBuffer, recXDiff*2+mouthBoxBuffer/2, recYDiff*2+mouthBoxBuffer/2],... % see the change in coordinates
'edgecolor','r');
numWhite = sum(sum(mouthsquare));
He said to use two sum()'s because it gets the columns and rows of the contained pixels within the rectangle. numWhite always returns 178 and some decimal numbers.
If you have a 2D matrix M (this being -- for exmple -- an image), the way to count how many elements have the value 1 is:
count_1 = sum(M(:)==1)
or
count_1 = sum(reshape(M,1,[])==1)
If the target values are not exactly 1, but have a Δ-threshold of, let's say, +/- 0.02, then one should ask for:
count_1_pm02 = sum((M(:)>=0.98) & (M(:)<=1.02))
or the equivalent using reshape.