Please how can I store values of variable size vectors inside a loop for

image processing

7 Comments

Probably in a cell array, or a structure, or a table, or...
But you question does not have enough information to know exactly what you are doing and what you would need.
I would like doing a histogram partition based on local minima. so after derminated local minima points I want to take the portion between 2 points that is to say a vector of variable size each time we increment in the loop
@Mohamed: If you want a detailed and precise answer then you need to figure out how to formulate the question accordingly. It still sounds like cell arrays will be useful for you, but it's difficult to say more than that based on the limited information.
Take a look at this guide on how to ask questions:
Mohamed ouahidi's "Answer" moved here and formatted correctly:
The probleme exist in workspace the values of vectors subH(2) ....subH(n-1) are not stored
a=imread('pout.tif');
imshow(a); title('Original Image');
x = imhist(a);% vecteur d histogrm
maxHeight = max(x); % used to set limits for the histogram
% Split the original histogram into lenght of (idxX)
%idxX vector contains the minimas points of histogram image a
% first sub_histogram
subH_1=x( idxX(1): idxX(2) );
% Display the original and 1 sub-histograms
figure, stem(0:255, x,'.'); title('Original Histogram')
axis([0 260 0 maxHeight])
figure, stem( idxX(1): idxX(2,1) , subH_1, '.'); title('Sub-histogram 1');
axis([0 260 0 maxHeight])
% Display others sub-histograms
% n is known
for k= 2 : (n-1)
subH(k)= x( idxX(k) + 1 : idxX((k+1)) );
%figure;
%stem( idxX(k,1): idxX((k+1),1) , subHk, '.');
%axis([0 260 0 maxHeight])
end
@Mohamed ouahidi: what values does n have? If it is less than three then that loop will not run.
I use image 'cameraman.tif' in this case n = 44

Sign in to comment.

 Accepted Answer

" x( idxX(k) + 1 : idxX((k+1)) )" is a vector, so it should store in a vector too.
Use this one:
subH(k,:) = x( idxX(k) + 1 : idxX((k+1)) )';

7 Comments

''Amir Xz'' thank you for your answer,
I tried but it does not work
when I declare outside the loop
subH-2 = x( (idxX(2) + 1) : idxX(3));
°
°
subH-43 = x( (idxX(43) + 1) : idxX(44));
it works .
Okay, could you tell me what is "subH-2" 's size?
[m,n] = size(subH-2);
What is the m and n?
What about "subH-43"? Are all same?
subH-2 = x( (idxX(2) + 1) : idxX(3));
You cannot use a minus sign as part of a variable name. You could use
subH_2 = x( (idxX(2) + 1) : idxX(3));
or
subH{2} = x( (idxX(2) + 1) : idxX(3));
yes I mean subH_2 = x( (idxX(2) + 1) : idxX(3));
[M2 N2]=[2 1]....[M3 N3]=[4 1]....
[M4 N4]=[3 1] ...........
[M5 N5]=[2 1].............
[M42 N42]=[4 1].............
[M43 N43]=[2 1]
.... The size of vectors is not the same
Use cell array:
subH{k-1} = x( idxX(k) + 1 : idxX((k+1)) );
the problem is solved Thank you so much

Sign in to comment.

More Answers (0)

Categories

Products

Release

R2015a

Community Treasure Hunt

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

Start Hunting!