How to save maximum level values in the array
Mostrar comentarios más antiguos
Hello every one, I hope you are doing well. I have the following code which take the data as input which has shape 1x77564 then we convert it into 1000 samples. So there are 80 images were created using the following Code.
Each 1000 samples is convert into image as shown in the following code. after converting into image , i have applied a function which finds the number of level, maximum,minimum value
I want to save the Values in image which have maximum number of levels, and PRFValue with respect to levels for example if maximum levels are 4 then number of PRFValue are 4 and find the maximum and minimum value from that.
buffered = buffer(incomingdata, 1000);
for K = 1 : size(buffered,2)
thisdata = buffered(:,K);
outputdataset=thisdata.';
%work with thisdata
[numImages, lenImage] = size( outputdataset);
imSz = 1000; % assuming images are 1000x1000
imbg = false(10000,1000); % background "color"
imfg = ~imbg(1,1); % forground "color"
imSizeOut=[10000 1000]; % ImageSize
for k= 1:numImages
imData = round( outputdataset(k,:)); % get pattern
[~,Y] = meshgrid(1:1000,1:10000); % make a grid
% black and white image
BW = imbg;
BW(Y==imData)=imfg;
valueestimation=imbinarize(imresize(uint8(BW),imSizeOut));
% convert to uint8 (0 255)
valueestimationimage = im2uint8(valueestimation);
% resize (from 1000x1000)
SE=strel('disk',2);
BW=imdilate(BW,SE);
BW=imbinarize(imresize(uint8(BW),imSizeOut));
% convert to uint8 (0 255)
imoriginalestimate = im2uint8(BW);
imoriginal = flipud(imoriginalestimate);
[PRFValue,NumberofPulses,Levels,maximum,minimum]= DSLEVELFUNCTION1(imoriginalestimate )
end
end
%DS Function
function [PRFValue,NumberofPulses,Levels,maximum,minimum]= DSLEVELFUNCTION1(path)
rgbImage = path;
[rows, columns, numberOfColorChannels] = size(rgbImage);
if numberOfColorChannels > 1
grayImage = rgbImage(:, :, 3);
else
grayImage = rgbImage;
end
mask = grayImage >= 128;
SE= strel('disk',2);
BW = imclose(mask,SE);
BW=mask;
[labeledImage, numRegions] = bwlabel(BW);
props = regionprops(labeledImage,'all' );
allLengths = [props.Area];
% NumberofPulses=allLengths;
centroids = vertcat(props.Centroid);
whiteLineRows1 = centroids(:, 2);
maximum=max(whiteLineRows1);
minimum=min(whiteLineRows1);
DSPRFValue= unique(whiteLineRows1);
Levels=length(DSPRFValue);
% figure;
% hold on;
for k = 1 : numRegions
y1 = round(centroids(k, 2));
y2 = y1;
xt = props(k).Centroid(1);
yt = props(k).Centroid(2);
BB = props(k).BoundingBox;
% str = sprintf('DS Length %d at PRF %d', size(props(k).Image,2), y1);
%
% text(xt, yt, str, 'Color', 'r', 'HorizontalAlignment', 'Center', 'VerticalAlignment','bottom', 'FontSize',8);
% rectangle('Position', [BB(1),BB(2),BB(3),BB(4)],'EdgeColor','b','LineWidth',1) ;
PRFValue(k)=y1;
NumberofPulses(k)=size(props(k).Image,2);
% caption = sprintf('Dwell and Swtich Image with %d Levels', Levels);
% hold off
% title(caption, 'FontSize',10);
end
end
12 comentarios
Walter Roberson
el 15 de Ag. de 2022
buffered = buffer(incomingdata, 1000);
After that call, buffered will be an array with 1000 rows and as many columns as needed to store all of incomingdata
for K = 1 : size(buffered,2)
That would be up to the number of columns, quite a reasonable thing to loop for
thisdata = buffered(:,K);
That will give you one specific column, so 1000 values.
outputdataset=thisdata.';
That will convert the 1000 x 1 into a 1 x 1000. Sometimes there is good reason to do that, sometimes people do it because they are confused.
%work with thisdata
[numImages, lenImage] = size( outputdataset);
outputdataset is going to be 1 x 1000 at this point, so numImages is guaranteed to be 1 here
imSz = 1000; % assuming images are 1000x1000
But they are not. You extracted 1000 elements, so 1 x 1000 at this point.
for k= 1:numImages
numImages cannot be anything other than 1 at this point, so there is no point bothering to loop.
Stephen john
el 15 de Ag. de 2022
Stephen john
el 15 de Ag. de 2022
Benjamin Thompson
el 15 de Ag. de 2022
Anything wrong with the comments about your problem so far? Remember to accept good answers on this forum you will probably get more help if you have a history of that.
Stephen john
el 15 de Ag. de 2022
Walter Roberson
el 15 de Ag. de 2022
I am not going to bother to analyze further until you rewrite to fix the looping issue that I identified.
i want to find the value which have maximum Levels
Find the value of what?
Stephen john
el 15 de Ag. de 2022
Stephen john
el 15 de Ag. de 2022
Walter Roberson
el 15 de Ag. de 2022
buffered = buffer(incomingdata, 1000);
Is there any case in which buffer() can return a 3D array? Or does it always return a 2D array (or at least one column vector) ?
for K = 1 : size(buffered,2)
thisdata = buffered(:,K);
You are using one single : index, and one scalar column index. Is there any case in which that could return a 2D array, or will it always return a column vector?
outputdataset=thisdata.';
With thisdata always being a column vector, is there any situation in which outputdataset would become a 2D array after transposing the column vector, or will the result always be a row vector?
[numImages, lenImage] = size( outputdataset);
with outputdataset being a row vector, is there any case in which numImages can be anything other than 1 at that point?
imSz = 1000; % assuming images are 1000x1000
imbg = false(10000,1000); % background "color"
imfg = ~imbg(1,1); % forground "color"
imSizeOut=[10000 1000]; % ImageSize
for k= 1:numImages
are those statements inside the for K loop, or did I miss an end statement? You set the indentation as if they are outside the for K loop, but I believe you will find that they are inside for K . Using for k inside for K is mildly confusing but is valid as far as MATLAB is concerned, since K and k are considered different variable names.
sometime i get more than 1 numImages
No you do not -- not unless you have changed the code since you posted it. numImages is going to be exactly 1, always. There is no point looping over it.
Stephen john
el 15 de Ag. de 2022
Under what circumstances could outputdataset have more than one row at that point?
incomingdata = randn(1,17465);
buffered = buffer(incomingdata, 1000);
count_of_multiple_rows = 0;
for K = 1 : size(buffered,2)
thisdata = buffered(:,K);
outputdataset=thisdata.';
%work with thisdata
[numImages, lenImage] = size( outputdataset);
if numImages ~= 1
fprintf('Iteration #%d has %d rows\n', K, numImages);
count_of_multiple_rows = count_of_multiple_rows + 1;
end
end
if count_of_multiple_rows == 0
fprintf('As expected, numImages was 1 <strong>every</strong> time\n');
else
fprintf('Unexpectedly, numImages was different %d times\n', count_of_multiple_images);
end
Stephen john
el 15 de Ag. de 2022
Respuestas (0)
Categorías
Más información sobre Signal Attributes and Indexing en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!