필터 지우기
필터 지우기

how to divide a grayscale image into 8*8 blocks and return it from my function?

조회 수: 3 (최근 30일)
i do have a code, but it doesn't work quickly for 8*8. works perfectly for 32 and higher block sizes. it doesn't return the blocks either.
function y=segment1(f)
rgbImage = f;
imshow(rgbImage);
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
drawnow;
[rows columns numberOfColorBands] = size(rgbImage);
blockSizeR =8;
blockSizeC =8;
wholeBlockRows = floor(rows / blockSizeR);
blockVectorR = [blockSizeR * ones(1, wholeBlockRows), rem(rows, blockSizeR)];
wholeBlockCols = floor(columns / blockSizeC);
blockVectorC = [blockSizeC * ones(1, wholeBlockCols), rem(columns, blockSizeC)];
if numberOfColorBands > 1
ca = mat2cell(rgbImage, blockVectorR, blockVectorC, numberOfColorBands);
else
ca = mat2cell(rgbImage, blockVectorR, blockVectorC);
end
plotIndex = 1;
numPlotsR = size(ca, 1);
numPlotsC = size(ca, 2);
for r = 1 : numPlotsR
for c = 1 : numPlotsC
fprintf('plotindex = %d, c=%d, r=%d\n', plotIndex, c, r);
subplot(numPlotsR, numPlotsC, plotIndex);
rgbBlock=ca{r,c};
imshow(rgbBlock);
[rowsB columnsB numberOfColorBandsB] = size(rgbBlock);
caption = sprintf('Block #%d of %d\n%d rows by %d columns', plotIndex, numPlotsR*numPlotsC, rowsB, columnsB);
drawnow;
plotIndex = plotIndex + 1;
end
end
end

채택된 답변

Walter Roberson
Walter Roberson 2016년 3월 30일
Your code starts
function y=segment1(f)
so it will return whatever is stored in the variable "y" by the function. But you do not store anything into y, so it cannot return the blocks. You need to store the blocks in y.
  댓글 수: 4
chaitanya g p
chaitanya g p 2016년 4월 5일
hey. regarding the storing of value in y. how do i do that? please help me out.
Walter Roberson
Walter Roberson 2016년 4월 5일
What is your defined output type? What kind of variable do you need to return? What is it that needs to be returned?

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Red에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by