This is the image which i am testing.. And code for it is..
I = imread('9.png');
threshold = graythresh(I);
originalImage = im2bw(I, threshold);
i = bwareaopen(originalImage,350);
m = max(max(i));
[r c] = find(i == m);
fid = fopen('lalit1.txt','wt');
data = textread('lalit1.txt');
r = unique(data);
c = data(data(:,2)==i,1);
z(i,1) = mean([min(c) max(c)]);
fid = fopen('lalit2.txt','wt');
fileID = fopen('lalit2.txt');
C = textscan(fileID, '%f32 %f32');
nz = x ~= 0;
y = y(nz);
x = x(nz);
binaryImage = logical(accumarray( ceil([x(:), y(:)]), 1, [480 752]) );
Why this program shows error for this attached image.?
Please give me correction..
No products are associated with this question.
What do you think this code does on a binary image (badly named "i"):
m = max(max(i)); [r c] = find(i == m);
Yep, m is one, so it's the same as
[r c] = find(i);
Then you write all pixel locations to a file for some unknown reason. Then you read it all back in with this
data = textread('lalit1.txt'); r = unique(data);
but now r has unique values from all the rows and columns combined, which makes little sense. Then it continues to get crazier from then on. What are you trying to do? Whatever it is, I'm sure this is not the best way of doing it. I don't really understand what the for,c,z loop is supposed to do and why you're messing around with cell arrays, accumarray(), etc. Perhaps it's due to the lack of comments. But anyway, I'm sure there is a much easier way, if I just knew what you were trying to accomplish. Posting an image would help.
Nothing matches the equality test, so "c" becomes empty. The min and max of that are empty, the mean of emptiness is empty, and you then try to store that emptiness in a single array location. But a single array location is too big to store emptiness so you get the error.
Play games and win prizes!Learn more