Unable to perform assignment because the size of the left side is 465-by-680 and the size of the right side is 482-by-680.

1 次查看(过去 30 天)
I am trying to get the specefic row and colum where row or column is less the 255. Then a want to save them in a variable, becasue the row is not the same in both 2 images so it gives me assignment arror. How do i solve it
clc
clear all
for k = 100:101
img_i = imread(['D:\data-11\sir task\New folder (2)\qi\snr30i4ASK' num2str(k) '.png']);
% img_i = imread(img_i);
img_i = rgb2gray(img_i);
row_i = find(any(img_i<255,2));
first_rowi = row_i(1);
last_rowi = row_i(end);
col_i = find(any(img_i<255,1));
first_coli = col_i(1);
last_coli = col_i(end);
new_imgi = img_i(first_rowi:last_rowi, first_coli:last_coli);
% For Q image
img_q = imread(['D:\data-11\sir task\New folder (2)\q\snr30q4ASK' num2str(k) '.png']);
% img_q = imread(img_q);
img_q = rgb2gray(img_q);
row_q = find(any(img_q<255,2));
first_rowq = row_q(1);
last_rowq = row_q(end);
col_q = find(any(img_q<255,1));
first_colq = col_q(1);
last_colq = col_q(end);
new_imgq = img_q(first_rowq:last_rowq, first_colq:last_colq);
final_img(:,:,1) = new_imgi;
final_img(:,:,2) = new_imgq;
p = 'D:\data-11\sir task\New folder (2)\f'
cd(p)
save(['snr304ASKiq' num2str(k) '.mat'], 'p');
cd ..
close
end
I have also uploaded the png

采纳的回答

yanqi liu
yanqi liu 2021-11-24
sir,may be use the matrix data modify,such as
maxr = max([size(new_imgi,1) size(new_imgq,1)]);
if size(new_imgi,1) < maxr
new_imgi(maxr-size(new_imgi,1):maxr,:) = 255;
end
if size(new_imgq,1) < maxr
new_imgq(maxr-size(new_imgq,1):maxr,:) = 255;
end
the code is
clc; clear all; close all;
ims1 = {'https://ww2.mathworks.cn/matlabcentral/answers/uploaded_files/810454/snr30i4ASK100.png','https://ww2.mathworks.cn/matlabcentral/answers/uploaded_files/810459/snr30i4ASK101.png'};
ims2 = {'https://ww2.mathworks.cn/matlabcentral/answers/uploaded_files/810444/snr30q4ASK100.png','https://ww2.mathworks.cn/matlabcentral/answers/uploaded_files/810449/snr30q4ASK101.png'};
for k = 1:2
final_img=[];
img_i = imread(ims1{k});
% img_i = imread(img_i);
img_i = rgb2gray(img_i);
row_i = find(any(img_i<255,2));
first_rowi = row_i(1);
last_rowi = row_i(end);
col_i = find(any(img_i<255,1));
first_coli = col_i(1);
last_coli = col_i(end);
new_imgi = img_i(first_rowi:last_rowi, first_coli:last_coli);
% For Q image
img_q = imread(ims2{k});
% img_q = imread(img_q);
img_q = rgb2gray(img_q);
row_q = find(any(img_q<255,2));
first_rowq = row_q(1);
last_rowq = row_q(end);
col_q = find(any(img_q<255,1));
first_colq = col_q(1);
last_colq = col_q(end);
new_imgq = img_q(first_rowq:last_rowq, first_colq:last_colq);
maxr = max([size(new_imgi,1) size(new_imgq,1)]);
if size(new_imgi,1) < maxr
new_imgi(maxr-size(new_imgi,1):maxr,:) = 255;
end
if size(new_imgq,1) < maxr
new_imgq(maxr-size(new_imgq,1):maxr,:) = 255;
end
final_img(:,:,1) = new_imgi;
final_img(:,:,2) = new_imgq;
% p = 'D:\data-11\sir task\New folder (2)\f'
% cd(p)
% save(['snr304ASKiq' num2str(k) '.mat'], 'p');
% cd ..
% close
end
  2 个评论
john karli
john karli 2021-11-24
Thank you it works.
One more question i want to ask that, as i have more images then my final_img variable wil make some time with dimension 509x680x2 and some time 482x680x2. I want to make my final_img variable standrad like either the dimension 509x680x2 or 482x680x2 it should be 524x680x2.
yanqi liu
yanqi liu 2021-11-24
yes,sir,if the max row is 524,may be just set
maxr = max([524, size(new_imgi,1) size(new_imgq,1)]);
if size(new_imgi,1) < maxr
new_imgi(maxr-size(new_imgi,1):maxr,:) = 255;
end
if size(new_imgq,1) < maxr
new_imgq(maxr-size(new_imgq,1):maxr,:) = 255;
end

请先登录,再进行评论。

更多回答(1 个)

Walter Roberson
Walter Roberson 2021-11-23
img_i = imread(['D:\data-11\sir task\New folder (2)\qi\snr30i4ASK' num2str(k) '.png']);
[...]
new_imgi = img_i(first_rowi:last_rowi, first_coli:last_coli);
new_imgi is sized based on information exclusively from the first image.
img_q = imread(['D:\data-11\sir task\New folder (2)\q\snr30q4ASK' num2str(k) '.png']);
[...]
new_imgq = img_q(first_rowq:last_rowq, first_colq:last_colq);
new_imgq is sized based on information exclusively from the second image.
final_img(:,:,1) = new_imgi;
final_img(:,:,2) = new_imgq;
but there you expect the two to be the same size.
  2 个评论
john karli
john karli 2021-11-23
i know these both are not in the same size in rows but column are same. so i want to pad the value of 255 to that row wich are less. For example
row_i = 482x1
row_q = 474x1
i want to add 255 in row_q to make is equal to row_i. the final should be
row_i = 482x1
row_q = 482x1
Walter Roberson
Walter Roberson 2021-11-24
This is probably not what you want to do.
Suppose you have matrix A that is white (255) for the first 5 columns, then has 5 columns of data, then has 5 columns of white -- 15 columns total, of which columns 6, 7, 8, 9, 10 are "interesting".
Now suppose you have matrix B that is white (255) for the first 3 columns, then has 3 columns of "interesting" data, and then has 9 columns of white -- 15 columns total, of which columns 4, 5, 6 are "interesting".
You do your extracting, and you come out with a matrix with 5 columns for A. You do your extracting, and you come out with a matrix with 3 columns for B. Now before you wanted to pad them to a common size, so you would leave the subset of A alone, and you would pad the subset of B with two columns of white, and then put the two together. Or now you want to pad them to the original size, so you would take the subset of A and add 10 columns of white, and you would take the subset of B and add 12 columns of white, and put those together.
But do these make sense to do?? I don't think so! Your original column 6 of A is now aligned with your original column 4 of B
I would suggest that you either want to trim off the leading and trailing rows that are white in both arrays... or else that you just want to put the arrays together unchanged. Your array A that has 5 columns of leading white... if you were to extract the non-white columns and then pad with white on both sides to align it with B... you would get exactly the same A as you already had. (Unless, that is, you pad with something different than 255.)

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Images 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by