Calculate Spray cone angle
4 views (last 30 days)
Show older comments
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/662970/image.png)
I have an image of result of multi hole injector
and I want to get the cone angle of one hole.
Therefore, this is my code, but the code give me wrong angle and I want to get the result that the background of clipped image is gone but the background still remains white. How can I fix it ??
clear all
close all
clc
casenumber = 1;
for casenumber=1:1
load_path = strcat('D:\JY\HHM\Spray_diesel\tecplot_image\clipped'); %경로지정
subt_path = strcat(load_path,'\subt');
save_path = strcat(load_path, 'D:\JY\HHM\Spray_diesel\tecplot_image\clipped'); %저장 경로
disp(save_path)
cd(load_path)
k=0;
yt=1168/2; yb=1168; xl=1; xr=1168; %% 사진 크기 기준
center=(xr-xl)/2;
Ratio=100/(xr-xl);
length=yb-yt+1;
%% Mie scattering
i=10;
for j=1:50
k=k+1;
cd(load_path)
filename=strcat('0.00', int2str(i), '.png');
filenamebw=strcat('0.00',int2str(i),'_bw','.png');
if i<=1000
filename=strcat('0.000', int2str(i), '.png');
filenamebw=strcat('0.000',int2str(i),'_bw','.png');
end
if i<=100
filename=strcat('0.0000', int2str(i), '.png');
filenamebw=strcat('0.0000',int2str(i),'_bw','.png');
end
i=i+100 ;
I_m=imread(filename); %% 사진 읽기
%I_m=I_m(yt:yb,xl:xr,:); %% 사진 자르기 [yt:yb,xl:xr]
%triangle_x=[center-200 center center+200];
%triangle_y=[yb yt yb];
%I_masked=roipoly(I_m,triangle_x,triangle_y);
Isize=size(I_m);
mask = poly2mask([center-200 center center center+200],[yb yt yt yb], Isize(1,1), Isize(1,2));
I_masked = bsxfun(@times,I_m,cast(mask,class(I_m)));
I_masked =I_masked(yt:yb,xl:xr);
mask =mask(yt:yb,xl:xr);
%I_masked = bsxfun(@times,I_m,cast(mask,class(I_m)));
%I_masked=image(I_masked,'alphadata',1-double(all(mask,3)));
%I_masked=bsxfun(@eq,I_masked,mask);
%I_masked=eq(I_masked,mask);
%mask=bsxfun(@eq,I_masked,reshape([0 0 0],1,1,3));
%I_masked=image(I_masked,'alphadata',1-double(all(mask,3)));
%I_masked=imread(I_masked);
%% Mie image processing
I_masked_modified=I_masked;
%I_masked_modified=immultiply(I_masked,3.5); %% 이미지 밝기 보정
imwrite(uint8(255 - I_masked_modified),filenamebw); %% 이미지 흑백 반전
I_masked_modified_inversed = imread(filenamebw);
threshhold_m=245/256;
threshhold=100/256;
BinaryI_m = im2bw(I_masked_modified_inversed,threshhold_m); %% 2진 사진으로 변경
I_masked = im2bw(I_masked_modified_inversed,threshhold);
seD1 = strel('disk',1); %% 원형 모양 벡터 생성 1포인트
BinaryI_m = imdilate(BinaryI_m, seD1); %% 원형 모양 벡터로 이미지 부풀리기
BinaryI_m = imdilate(BinaryI_m, seD1);
BinaryI_m = imdilate(BinaryI_m, seD1);
BinaryI_m = imdilate(BinaryI_m, seD1);
BinaryI_m = imdilate(BinaryI_m, seD1);
BinaryI_m = imfill(BinaryI_m, 'holes'); %% 구멍난 부분 메우기
BinaryI_m = imerode(BinaryI_m, seD1); %%다시 깎기
BinaryI_m = imerode(BinaryI_m, seD1);
BinaryI_m = imerode(BinaryI_m, seD1);
BinaryI_m = imerode(BinaryI_m, seD1);
BinaryI_m = imerode(BinaryI_m, seD1);
Area_m=bwarea(BinaryI_m); %%bwarea=이진영상의 객체 면적
%
if Area_m>0
%% %%%%%%%%%%%%%% penetration length %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 인젝션 팁 시작지점은 사진에서 직접 좌표를 찾아서 [x,y]좌표를 넣어줘야한다.
L_m=logical(BinaryI_m);
stats_m = regionprops(L_m, 'Area', 'Centroid','BoundingBox'); %%regionprops=이진영상의속성측정
areas_m = [stats_m.Area];
BoundingBox_value = [stats_m.BoundingBox];
[m,n] = size(BoundingBox_value) ;
xbottom_length=0;
for l=8:4:n
bottom_length = ((BoundingBox_value(l)+BoundingBox_value(l-2)-0.5)*50/length) ;
if xbottom_length<bottom_length
xbottom_length = bottom_length ;
end
end
pene(k,1)= (i)*0.0001
pene(k,2) = xbottom_length
%Table = table(pene,xbottom_length)
end
BWboundary=bwboundaries(BinaryI_m);
[x,y]=size(BWboundary);
%% cone angle
I_2=BinaryI_m+mask;
[rows,columns]=size(BinaryI_m);
leftedge = zeros(1,rows);
rightedge = zeros(1,rows);
rows=rows/50;
for row=1:rows
%thisrow=BinaryI_m(row,:);
leftindex = find(I_2==2, 1, 'first');
if ~isempty(leftindex)
leftedge(row)=leftindex;
rightedge(row)=find(I_2==2, 1, 'last');
X=1:585;
Y = leftedge(X);
leftCoefficients = polyfit(X, Y, 1);
leftAngle = atand(leftCoefficients(1));
Y = rightedge(X);
rightCoefficients = polyfit(X, Y, 1);
rightAngle = atand(rightCoefficients(1));
coneAngle = abs(leftAngle) + abs(rightAngle);
%coneAngle = coneAngle*cosd(15) ;
end
end
result = table((i)*0.0001,xbottom_length,leftAngle,rightAngle,coneAngle)
%% 이미지 출력
figure(1)
imshow(I_masked);
hold on
for j=1:x
C_m=cell2mat(BWboundary(j,1));
plot(C_m(:,2),C_m(:,1), 'y','LineWidth',2)
%yy=zeros(20,1);
%yy(j,1)=max(C_m(:,1));
hold on
end
hold off
% BWoutline = bwperim(BW_final1_m);
% Segout = I_obj_m;
% Segout(BWoutline) = 255;
% figure (2); imshow(Segout);
% yyy=max(yy);
%
% P_distance_m=(yyy-offset)*Ratio;
%
% LiquidArea_m(i, casenumber)=Area_m;
% LiquidPL_m(i, casenumber)=P_distance_m;
% save_path=save_path;
%if exist(save_path,'dir')==0
% mkdir save_path
% end
% imwrite(I_mm, savename);
%cd save_path
%print('-djpeg', savename)
end
end
0 Comments
Answers (0)
See Also
Categories
Find more on Resizing and Reshaping Matrices in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!