How to save maximum level values in the array

2 views (last 30 days)
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 Comments
Stephen john
Stephen john on 15 Aug 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

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!