How to save maximum level values in the array

조회 수: 3 (최근 30일)
Stephen john
Stephen john 2022년 8월 15일
댓글: Stephen john 2022년 8월 15일
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
Walter Roberson
Walter Roberson 2022년 8월 15일
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 2022년 8월 15일
@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

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by