現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
How to solve the problem?
2 ビュー (過去 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 で Number Theory についてさらに検索
タグ
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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 (한국어)