some portion of the code rest is not working,,please help me

1 view (last 30 days)
A=imread('101_1.tif');
figure,imshow(A);
Img=A;
%WINDOW SIZE
M=10;
N=20;
mid_val=round((M*N)/2);
%FIND THE NUMBER OF ROWS AND COLUMNS TO BE PADDED WITH ZERO
in=0;
for i=1:M
for j=1:N
in=in+1;
if(in==mid_val)
PadM=i-1;
PadN=j-1;
break;
end
end
end
%PADDING THE IMAGE WITH ZERO ON ALL SIDES
B=padarray(A,[PadM,PadN]);
for i= 1:size(B,1)-((PadM*2)+1)
for j=1:size(B,2)-((PadN*2)+1)
cdf=zeros(256,1);
inc=1;
for x=1:M
for y=1:N
%FIND THE MIDDLE ELEMENT IN THE WINDOW
if(inc==mid_val)
ele=B(i+x-1,j+y-1)+1;
end
pos=B(i+x-1,j+y-1)+1;
cdf(pos)=cdf(pos)+1;
inc=inc+1;
end
end
%COMPUTE THE CDF FOR THE VALUES IN THE WINDOW
for l=2:256
cdf(l)=cdf(l)+cdf(l-1);
end
Img(i,j)=round(cdf(ele)/(M*N)*255);
end
end
figure,imshow(Img);
figure
imhist(A);
figure
imhist(Img);
%IM2BW Convert image to black and white by thresholding.
% BW = IM2BW(X,MAP,LEVEL) converts the indexed image X with
% colormap MAP to a black and white intensity image BW.
% BW is 0 (black) for all pixels with luminance less
% than LEVEL and 1 (white) for all other values.
%
% BW = IM2BW(I,LEVEL) converts the gray level intensity image
% I to black and white. BW is 0 (black) for all pixels with
% value less than LEVEL and 1 (white) for all other values.
%
% BW = IM2BW(R,G,B,LEVEL) converts the RGB image to black
% and white. BW is 0 (black) for all pixels with luminance
% less than LEVEL and 1 (white) for all other values.
%
% See also IND2GRAY, RGB2GRAY
I = imread('101_1.tif');
figure
imshow(I)
title('Original Image')
BW = imbinarize(I,'adaptive','ForegroundPolarity','dark','Sensitivity',0.4);
figure
imshow(BW)
title('Binary Version of Image')
rest of part dose not working:
function [p,z] = direction(image,blocksize,noShow)
%image=adaptiveThres(image,16,0);
[w,h] = size(image);
direct = zeros(w,h);
gradient_times_value = zeros(w,h);
gradient_sq_minus_value = zeros(w,h);
gradient_for_bg_under = zeros(w,h);
W = blocksize;
theta = 0;
sum_value = 1;
bg_certainty = 0;
blockIndex = zeros(ceil(w/W),ceil(h/W));
%directionIndex = zeros(ceil(w/W),ceil(h/W));
times_value = 0;
minus_value = 0;
center = [];
filter_gradient = fspecial('sobel');
%to get x gradient
I_horizontal = filter2(filter_gradient,image);
%to get y gradient
filter_gradient = transpose(filter_gradient);
I_vertical = filter2(filter_gradient,image);
gradient_times_value=I_horizontal.*I_vertical;
gradient_sq_minus_value=(I_vertical - I_horizontal).*(I_vertical+I_horizontal);
gradient_for_bg_under = (I_horizontal.*I_horizontal) + (I_vertical.*I_vertical);
for i=1:W:w
for j=1:W:h
if j+W-1 < h & i+W-1 < w
times_value = sum(sum(gradient_times_value(i:i+W-1, j:j+W-1)));
minus_value = sum(sum(gradient_sq_minus_value(i:i+W-1, j:j+W-1)));
sum_value = sum(sum(gradient_for_bg_under(i:i+W-1, j:j+W-1)));
bg_certainty = 0;
theta = 0;
if sum_value ~= 0 & times_value ~=0
%if sum_value ~= 0 & minus_value ~= 0 & times_value ~= 0
bg_certainty = (times_value*times_value + minus_value*minus_value)/(W*W*sum_value);
if bg_certainty > 0.05
blockIndex(ceil(i/W),ceil(j/W)) = 1;
%tan_value = atan2(minus_value,2*times_value);
tan_value = atan2(2*times_value,minus_value);
theta = (tan_value)/2 ;
theta = theta+pi/2;
center = [center;[round(i + (W-1)/2),round(j + (W-1)/2),theta]];
end
end
end
times_value = 0;
minus_value = 0;
sum_value = 0;
end
end
if nargin == 2
imagesc(direct);
hold on;
[u,v] = pol2cart(center(:,3),8);
quiver(center(:,2),center(:,1),u,v,0,'g');
hold off;
end
x = bwlabel(blockIndex,4);
y = bwmorph(x,'close');
z = bwmorph(y,'open');
p = bwperim(z);
end
%(to extract ROI)
function [roiImg,roiBound,roiArea] = drawROI(in,inBound,inArea,noShow)
[iw,ih]=size(in);
tmplate = zeros(iw,ih);
[w,h] = size(inArea);
tmp=zeros(iw,ih);
left = 1;
right = h;
upper = 1;
bottom = w;
le2ri = sum(inBound);
roiColumn = find(le2ri>0);
left = min(roiColumn);
right = max(roiColumn);
tr_bound = inBound';
up2dw=sum(tr_bound);
roiRow = find(up2dw>0);
upper = min(roiRow);
bottom = max(roiRow);
%cut out the ROI region image
%show background,bound,innerArea with different gray
intensity:0,100,200
for i = upper:1:bottom
for j = left:1:right
if inBound(i,j) == 135
tmplate(16*i-15:16*i,16*j-15:16*j) = 200;
tmp(16*i-15:16*i,16*j-15:16*j) = 1;
elseif inArea(i,j) == 1 & inBound(i,j) ~=1
tmplate(16*i-15:16*i,16*j-15:16*j) = 100;
tmp(16*i-15:16*i,16*j-15:16*j) = 1;
end
end
end
in=in.*tmp;
roiImg = in(16*upper-15:16*bottom,16*left-15:16*right);
roiBound = inBound(upper:bottom,left:right);
roiArea = inArea(upper:bottom,left:right);
%inner area
roiArea = im2double(roiArea) - im2double(roiBound);
if nargin == 3
colormap(gray);
imagesc(tmplate);
end
end

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!