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 view (last 30 days)
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

Accepted Answer

yanqi liu
yanqi liu on 24 Nov 2021
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 Comments
john karli
john karli on 24 Nov 2021
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 on 24 Nov 2021
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

Sign in to comment.

More Answers (1)

Walter Roberson
Walter Roberson on 23 Nov 2021
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 Comments
john karli
john karli on 23 Nov 2021
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 on 24 Nov 2021
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.)

Sign in to comment.

Categories

Find more on Image Processing and Computer Vision in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!