How to save maximum level values in the array

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

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
Stephen john el 15 de Ag. de 2022
@Walter Roberson imoriginalestimate is the images that were created and pass it to the function which calculate [PRFValue,NumberofPulses,Levels,maximum,minimum]
i want to find the value which have maximum Levels, When we find maximum Levels, then we have the PRFValue for this
Stephen john
Stephen john el 15 de Ag. de 2022
@Walter Roberson have you understand my problem?
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
Stephen john el 15 de Ag. de 2022
@Benjamin Thompson No, but still looking for the solution. Have you understand my problem?
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?
@Walter Roberson When the image are created then we pass through the function , use the following line, Each image is pass through this function it returns PRFValue,NumberofPulses,Levels,maximum,minimum.
I want to save the matrix which have Highest number of Levels and save the corresponding PRFValue,NumberofPulses,maximum,minimum
[PRFValue,NumberofPulses,Levels,maximum,minimum]=DSLEVELFUNCTION1(imoriginalestimate )
Stephen john
Stephen john el 15 de Ag. de 2022
@Walter Roberson I have used the loop because sometime i get more than 1 numImages thats why i used that loop.
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
Stephen john el 15 de Ag. de 2022
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) ?
  • It always return 2D array ( at least one column vector)
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?
  • it always return a column vector
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?
  • will the result always be a row vector
with outputdataset being a row vector, is there any case in which numImages can be anything other than 1 at that point?
  • Each row consists of 1000 samples and that will be used to create an image.
the small k is used if there are rows more then 1. then we apply this k.
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
As expected, numImages was 1 every time
Stephen john
Stephen john el 15 de Ag. de 2022
@Walter Roberson Okay let say its one every time, then Please solve this method. When the image are created then we pass through the function , use the following line, Each image is pass through this function it returns PRFValue,NumberofPulses,Levels,maximum,minimum.
I want to save the matrix which have Highest number of Levels and save the corresponding PRFValue,NumberofPulses,maximum,minimum

Iniciar sesión para comentar.

Respuestas (0)

Productos

Versión

R2022a

Preguntada:

el 15 de Ag. de 2022

Comentada:

el 15 de Ag. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by