이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
How to solve the problem?
조회 수: 3 (최근 30일)
이전 댓글 표시
I have a 198x198 matrix, an image. I need to get 3x3 matrices each from the above matrix. Total, 22 matrices, how to access each of them? can somebody help me with the code??
답변 (1개)
Walter Roberson
2018년 4월 26일
blocks = mat2cell(YourMatrix, 3*ones(1,22), 3*ones(1,22));
then you would access (for example) blocks{7,4) to give you the 7th block of 3 down, 4'th block of 3 across.
댓글 수: 17
Darsana P M
2018년 4월 26일
blocks = mat2cell(L0, 3*ones(1,22), 3*ones(1,22));
I got an error.here,L0=200x200 matrix?
Walter Roberson
2018년 4월 26일
You said before your arrays were 198. That size divides neatly into 3x3 arrays. When you have 200x200 then you would have 2 left over after dividing into groups of 3. What do you want to do with the extra 2x3 and 3x2 and the corner 2x2?
Walter Roberson
2018년 4월 26일
[r, c] = size(L0);
temp = L0;
temp( r+1:ceil(r/3)*3, c+1:ceil(c/3)*3 ) = 0;
[r, c] = size(temp);
blocks = mat2cell(temp, 3*ones(1,r/3), 3*ones(1,c/3));
clear temp;
Darsana P M
2018년 4월 26일
Sir,the code works fine. From this how to extract 3x3 matrix and then perform certain operations, and then put them into an new matrix,200x200?
Walter Roberson
2018년 4월 26일
this_block = blocks{7,4}; %extract 3x3 matrix
new_block = reshape(sort(this_block(:)), size(this_block)); %perform certain operations
new_blocks{7,4} = new_block;
new_matrix = cell2mat(new_blocks);
new_matrix = new_matrix(1:size(L0,1), 1:size(L0,2)); %trim out padding
Darsana P M
2018년 4월 26일
Index exceeds matrix dimensions.
Error in daru (line 49) new_matrix = new_matrix(1:size(L0,1), 1:size(L0,2)); %trim out padding Sir I got this error?
Walter Roberson
2018년 4월 26일
new_blocks = blocks;
before the above code would ensure that the blocks not changed were copied over.
Your operations would replace
new_block = reshape(sort(this_block(:)), size(this_block)); %perform certain operations
Do whatever operations you need to this_block, assigning the result to new_block .
Darsana P M
2018년 4월 27일
sir,the dimensions became wrong.
Index exceeds matrix dimensions.
Error in daru (line 60) new_matrix = new_matrix(1:size(L0,1), 1:size(L0,2)); %trim out padding
Sir, i have a doubt, after doing all these operations, will a get a 3x3 matrix or the entire image, 200x200??
Walter Roberson
2018년 4월 27일
>> L0 = imread('cameraman.tif');
>> [r, c] = size(L0);
temp = L0;
temp( r+1:ceil(r/3)*3, c+1:ceil(c/3)*3 ) = 0;
[r, c] = size(temp);
blocks = mat2cell(temp, 3*ones(1,r/3), 3*ones(1,c/3));
clear temp;
>> size(blocks)
ans =
86 86
>> new_blocks = blocks;
>>
this_block = blocks{7,4}; %extract 3x3 matrix
new_block = reshape(sort(this_block(:)), size(this_block)); %perform certain operations
new_blocks{7,4} = new_block;
new_matrix = cell2mat(new_blocks);
new_matrix = new_matrix(1:size(L0,1), 1:size(L0,2)); %trim out padding
>> size(new_matrix)
ans =
256 256
>> size(L0)
ans =
256 256
>> image(new_matrix)
>> colormap(gray(256))
Darsana P M
2018년 4월 27일
clc;
close all;
clear all;
k=0;
I = dicomread('C:\Users\Click Me\Desktop\NIELIT\Output images\dic5.dcm');
info = dicominfo('C:\Users\Click Me\Desktop\NIELIT\Output images\dic5.dcm');
figure(1);
image(I);
h=rgb2gray(I);
imhist(h);
N= 257;
l=zeros(200,400);
B_mat=h(1:200,:);
figure(2);
image(B_mat);
%Rot=[-15,-20,60,20;52,-39,0,25;36,48,32,13;12,43,23,76];
Rot=[-15,-20,60;52,-39,0;36,48,32]
o=[3 4 2 6];
q1=o;
q2=qInv(q1);
L0=B_mat(:,1:200);
R0=B_mat(:,201:400);
h=qGetR(R0);
[M,N]=size(L0);
b=3;
M=M-rem(M,b);
N=N-rem(N,b);
L0=L0;
%A=zeros(200,200);
lo=L0(1:200,1:200);
%s=size(lo);
% dim=198;
% [row column]=size(lo);
% count=0;
% Bigblock=zeros(198,198);
[r, c] = size(L0);
temp = L0;
temp( r+1:ceil(r/3)*3, c+1:ceil(c/3)*3 ) = 0;
[r, c] = size(temp);
blocks = mat2cell(temp, 3*ones(1,r/3), 3*ones(1,c/3));
%J=cell2mat(blocks);
clear temp;
this_block = blocks{7,4};
%extract 3x3 matrix
n1=(this_block).*Rot;
L1=mod(n1,N);
%B=cat(dim,Bigblock,block);
R1=(L1 + this_block);
m=mod(R1,N);
%new_block=this_block;
%new_block=mat2cell(blocks);
%new_block = reshape(sort(this_block(:)), size(this_block)); %perform certain operations
new_blocks{7,4} = new_block;
new_matrix = cell2mat(new_blocks);
%new_blocks= cell2mat(blocks);
new_matrix = new_matrix(1:size(L0,1), 1:size(L0,2)); %trim out padding
Sir, Thanks a lot for your help.But could you please help me, for me there is an issue doing .* multiplication step.
Walter Roberson
2018년 4월 27일
The result if your dicomread() is likely to be either uint8 or int16, maybe uint16. rgb2gray() will preserve that data type. The way you extract data into L0 looks like it will preserve that data type. The mat2cell() will preserve the data type.
So this_block should be the same data type as dicomread() returned, probably either uint8 or int16. You try to .* with double data. That would be trying to calculate with mixed data types. MATLAB is likely to refuse.
If MATLAB did not refuse, then it looks plausible to me that some of the entries might try to be negative even though the original values were positive. If so then you have a problem, because if the original were uint8 then negatives are not possible and the negatives are going to be converted to 0.
Try
n1 = double(this_block).*Rot;
and when you go to write back into the array,
new_blocks{7,4} = cast(new_block, class(this_block));
which will force the output to be the same data type as the original.
Darsana P M
2018년 4월 27일
Thank you sir
Error using cast Conversion to double from cell is not possible.
Error in daru (line 65) new_blocks{7,4} = cast(new_block,class(this_block));
Sir, I got this error.
참고 항목
카테고리
Help Center 및 File Exchange에서 Get Started with Statistics and Machine Learning Toolbox에 대해 자세히 알아보기
태그
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
아시아 태평양
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)
